Skip to content

Commit

Permalink
Add tests for CI functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ds58 committed Sep 24, 2024
1 parent 0a8e4ba commit 74e5c03
Show file tree
Hide file tree
Showing 19 changed files with 528 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/test/java/us/ihmc/ci/CategoriesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import us.ihmc.build.GradleTestingToolsKt;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

@Tag("categories-test")
public class CategoriesTest
{
@Test
public void testAllTestsRun() throws IOException
{
String projectName = "categories";
GradleTestingToolsKt.runGradleTask("-v", projectName);
String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName);
Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL"));
String output = GradleTestingToolsKt.runGradleTask("test --info -Pcategory=all", projectName);
Assertions.assertTrue(output.contains("BUILD FAILED"));

System.out.println("Working dir: " + Paths.get(".").toAbsolutePath());
String results = Files.readString(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html"));
System.out.println(results);
// Asserts 11 tests pass, 1 test fails, 0 tests ignored
Assertions.assertTrue(results.contains(
"<a href=\"packages/us.ihmc.ci.html\">us.ihmc.ci</a>" + System.lineSeparator() + "</td>" + System.lineSeparator() + "<td>9</td>"
+ System.lineSeparator() + "<td>1</td>" + System.lineSeparator() + "<td>0</td>"));
}

@Test
public void testFastTestsRun() throws IOException
{
String projectName = "categories";
GradleTestingToolsKt.runGradleTask("-v", projectName);
String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName);
Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL"));
String output = GradleTestingToolsKt.runGradleTask("test --info -PincludeTags=fast", projectName);
Assertions.assertTrue(output.contains("BUILD SUCCESSFUL"));

System.out.println("Working dir: " + Paths.get(".").toAbsolutePath());
String results = Files.readString(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html"));
System.out.println(results);
// Asserts 5 tests pass, 0 test fails, 0 tests ignored
Assertions.assertTrue(results.contains(
"<a href=\"packages/us.ihmc.ci.html\">us.ihmc.ci</a>" + System.lineSeparator() + "</td>" + System.lineSeparator() + "<td>4</td>"
+ System.lineSeparator() + "<td>0</td>" + System.lineSeparator() + "<td>0</td>"));
}
}
5 changes: 5 additions & 0 deletions src/test/java/us/ihmc/ci/CategorizedExtendingExtreme.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package us.ihmc.ci;

public class CategorizedExtendingExtreme // extends CategorizedAbstractTest
{
}
12 changes: 12 additions & 0 deletions src/test/java/us/ihmc/ci/CategorizedExtendingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Test;

public class CategorizedExtendingTest //extends CategorizedAbstractTest
{
@Test
public void imAndExtendingTest()
{
//super.imAnAbstractTest();
}
}
48 changes: 48 additions & 0 deletions src/test/java/us/ihmc/ci/CategorizedTests1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.api.parallel.ResourceAccessMode;
import org.junit.jupiter.api.parallel.ResourceLock;

public class CategorizedTests1
{
@Tag("fast")
@Test
public void fastTest() throws InterruptedException
{
}

@Test
public void untaggedTest()
{

}

@Disabled
@Tag("failing")
@Test
public void failingTest() throws InterruptedException
{
Assertions.fail();
}

@ResourceLock(value = "File.txt", mode = ResourceAccessMode.READ_WRITE)
@Execution(ExecutionMode.SAME_THREAD)
@Tag("slow")
@Test
public void slowTest() throws InterruptedException
{
}

@Tag("fast")
@Tag("needs-gpu")
@Test
public void gpuTest() throws InterruptedException
{
}
}
31 changes: 31 additions & 0 deletions src/test/java/us/ihmc/ci/CategorizedTests2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

public class CategorizedTests2
{
@Tag("fast")
@Test
public void fastTest() throws InterruptedException
{
}

@Test
public void untaggedTest() throws InterruptedException
{
}

@Tag("slow")
@Test
public void slowTest() throws InterruptedException
{
}

@Tag("fast")
@Tag("needs-gpu")
@Test
public void gpuTest() throws InterruptedException
{
}
}
50 changes: 50 additions & 0 deletions src/test/java/us/ihmc/ci/ParallelExecutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import us.ihmc.build.GradleTestingToolsKt;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ParallelExecutionTest
{
@Test
public void testAllTestsRun() throws IOException
{
String projectName = "categories";
GradleTestingToolsKt.runGradleTask("-v", projectName);
String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName);
Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL"));
String output = GradleTestingToolsKt.runGradleTask("test --info -Pcategory=all", projectName);
Assertions.assertTrue(output.contains("BUILD FAILED"));

System.out.println("Working dir: " + Paths.get(".").toAbsolutePath());
String results = new String(Files.readAllBytes(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html")));
System.out.println(results);
// Asserts 11 tests pass, 1 test fails, 0 tests ignored
Assertions.assertTrue(results.contains(
"<a href=\"packages/us.ihmc.ci.html\">us.ihmc.ci</a>" + System.lineSeparator() + "</td>" + System.lineSeparator() + "<td>9</td>"
+ System.lineSeparator() + "<td>1</td>" + System.lineSeparator() + "<td>0</td>"));
}

@Test
public void testFastTestsRun() throws IOException
{
String projectName = "categories";
GradleTestingToolsKt.runGradleTask("-v", projectName);
String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName);
Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL"));
String output = GradleTestingToolsKt.runGradleTask("test --info -Pcategory=fast", projectName);
Assertions.assertTrue(output.contains("BUILD SUCCESSFUL"));

System.out.println("Working dir: " + Paths.get(".").toAbsolutePath());
String results = new String(Files.readAllBytes(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html")));
System.out.println(results);
// Asserts 5 tests pass, 0 test fails, 0 tests ignored
Assertions.assertTrue(results.contains(
"<a href=\"packages/us.ihmc.ci.html\">us.ihmc.ci</a>" + System.lineSeparator() + "</td>" + System.lineSeparator() + "<td>4</td>"
+ System.lineSeparator() + "<td>0</td>" + System.lineSeparator() + "<td>0</td>"));
}
}
31 changes: 31 additions & 0 deletions tests/categories/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id("us.ihmc.ihmc-build")
id("us.ihmc.log-tools-plugin") version "0.6.3"
id("us.ihmc.ihmc-ci") version "7.7"
id("us.ihmc.ihmc-cd") version "1.23"
}

ihmc {
group = "us.ihmc"
version = "0.1.0"
vcsUrl = "https://your.vcs/url"
openSource = true

configureDependencyResolution()
configurePublications()
}

//categories.configure("all") {
//
//}

//ihmc.sourceSetProject("test").tasks.named("test", Test::class.java) {
//
//}

mainDependencies {
api("org.apache.commons:commons-lang3:3.12.0")
}

testDependencies {
}
20 changes: 20 additions & 0 deletions tests/categories/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
kebabCasedName = categories
pascalCasedName = Categories
extraSourceSets = ["test"]
publishUrl = local
compositeSearchHeight = 0
excludeFromCompositeBuild = false
artifactoryUsername = unset_username
artifactoryPassword = unset_password

# Test suite generator
disableJobCheck = true
crashOnEmptyJobs = false
crashOnMissingTimeouts = true
disableSuiteBalancing = false
maxSuiteDuration = 5.5
bambooUrl = "https://bamboo.ihmc.us/"
bambooPlanKeys = ["one", "two"]

includeTags = all
excludeTags = none
20 changes: 20 additions & 0 deletions tests/categories/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pluginManagement {
plugins {
id("us.ihmc.ihmc-build") version "0.29.3"
}
}

buildscript {
repositories {
maven { url = uri("https://plugins.gradle.org/m2/") }
mavenLocal()
}
dependencies {
classpath("us.ihmc:ihmc-build:0.29.3")
}
}

val ihmcSettingsConfigurator = us.ihmc.build.IHMCSettingsConfigurator(settings, logger, extra)
ihmcSettingsConfigurator.checkRequiredPropertiesAreSet()
ihmcSettingsConfigurator.configureExtraSourceSets()
ihmcSettingsConfigurator.findAndIncludeCompositeBuilds()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package us.ihmc;

public class BasicTestApplication
{
public static void main(String[] args)
{
System.out.println("Hello there. I'm some test code.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.time.Duration;

public abstract class CategorizedAbstractTest
{
public void imAnAbstractTest()
{

}

@Tag("fast")
@Test
public void someNonExtendedTest()
{
Assertions.assertTimeout(Duration.ofSeconds(30), () -> {

});
}
}
46 changes: 46 additions & 0 deletions tests/categories/src/test/java/us/ihmc/ci/CategorizedTests3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.api.parallel.ResourceAccessMode;
import org.junit.jupiter.api.parallel.ResourceLock;

public class CategorizedTests3
{
@Tag("fast")
@Test
public void fastTest() throws InterruptedException
{
}

@Test
public void untaggedTest()
{

}

@Tag("failing")
@Test
public void failingTest() throws InterruptedException
{
Assertions.fail();
}

@ResourceLock(value = "File.txt", mode = ResourceAccessMode.READ_WRITE)
@Execution(ExecutionMode.SAME_THREAD)
@Tag("slow")
@Test
public void slowTest() throws InterruptedException
{
}

@Tag("fast")
@Tag("needs-gpu")
@Test
public void gpuTest() throws InterruptedException
{
}
}
31 changes: 31 additions & 0 deletions tests/categories/src/test/java/us/ihmc/ci/CategorizedTests4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package us.ihmc.ci;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

public class CategorizedTests4
{
@Tag("fast")
@Test
public void fastTest() throws InterruptedException
{
}

@Test
public void untaggedTest() throws InterruptedException
{
}

@Tag("slow")
@Test
public void slowTest() throws InterruptedException
{
}

@Tag("fast")
@Tag("needs-gpu")
@Test
public void gpuTest() throws InterruptedException
{
}
}
Loading

0 comments on commit 74e5c03

Please sign in to comment.