diff --git a/.idea/misc.xml b/.idea/misc.xml index c696fb6..30a5bdc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,6 +4,7 @@ + diff --git a/src/bld/java/rife/bld/extension/TestNgOperationBuild.java b/src/bld/java/rife/bld/extension/TestNgOperationBuild.java index 890d916..ed53d3c 100644 --- a/src/bld/java/rife/bld/extension/TestNgOperationBuild.java +++ b/src/bld/java/rife/bld/extension/TestNgOperationBuild.java @@ -26,7 +26,8 @@ import java.util.List; import static rife.bld.dependencies.Repository.MAVEN_CENTRAL; import static rife.bld.dependencies.Repository.RIFE2_RELEASES; -import static rife.bld.dependencies.Scope.*; +import static rife.bld.dependencies.Scope.compile; +import static rife.bld.dependencies.Scope.test; import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING; public class TestNgOperationBuild extends Project { diff --git a/src/main/java/rife/bld/extension/TestNgOperation.java b/src/main/java/rife/bld/extension/TestNgOperation.java index c2e6f0f..b4dc366 100644 --- a/src/main/java/rife/bld/extension/TestNgOperation.java +++ b/src/main/java/rife/bld/extension/TestNgOperation.java @@ -52,6 +52,10 @@ public class TestNgOperation extends AbstractProcessOperation { * The suites to run. */ protected final List suites = new ArrayList<>(); + /** + * The classpath entries used for running tests. + */ + protected final List testClasspath = new ArrayList<>(); private final List args = new ArrayList<>(); private BaseProject project; @@ -118,9 +122,15 @@ public class TestNgOperation extends AbstractProcessOperation { args.clear(); args.add(javaTool()); + args.add("-cp"); - args.add(String.format("%s:%s:%s", Path.of(project.libTestDirectory().getPath(), "*"), - project.buildMainDirectory(), project.buildTestDirectory())); + if (testClasspath.isEmpty()) { + args.add(String.format("%s:%s:%s", Path.of(project.libTestDirectory().getPath(), "*"), + project.buildMainDirectory(), project.buildTestDirectory())); + } else { + args.add(String.join(":", testClasspath)); + } + args.add("org.testng.TestNG"); options.forEach((k, v) -> { @@ -406,6 +416,14 @@ public class TestNgOperation extends AbstractProcessOperation { return this; } + /** + * Specifies the classpath entries used to run tests. + */ + public TestNgOperation testClasspath(String... entry) { + testClasspath.addAll(Arrays.stream(entry).toList()); + return this; + } + /** * Specifies a jar file that contains test classes. If a {@code testng.xml} file is found at the root of that * jar file, it will be used, otherwise, all the test classes found in this jar file will be considered test diff --git a/src/test/java/rife/bld/extension/TestNgOperationTest.java b/src/test/java/rife/bld/extension/TestNgOperationTest.java index 3fec70b..bf61aaa 100644 --- a/src/test/java/rife/bld/extension/TestNgOperationTest.java +++ b/src/test/java/rife/bld/extension/TestNgOperationTest.java @@ -77,32 +77,42 @@ class TestNgOperationTest { assertThatThrownBy(() -> new TestNgOperation().fromProject(new Project()) .testClass("rife.bld.extension.TestNgSimpleTest") - .execute()).isInstanceOf(ExitStatusException.class); + .execute()) + .as("with testClass").isInstanceOf(ExitStatusException.class); assertThatThrownBy(() -> new TestNgOperation().fromProject(new Project()) .suites("src/test/resources/testng.xml") - .execute()).isInstanceOf(ExitStatusException.class); + .execute()) + .as("with suites").isInstanceOf(ExitStatusException.class); assertThatCode(() -> new TestNgOperation().fromProject(new Project()) .testClass("rife.bld.extension.TestNgSimpleTest") .methods("rife.bld.extension.TestNgSimpleTest.verifyHello") .execute()) - .doesNotThrowAnyException(); + .as("with methods").doesNotThrowAnyException(); assertThatCode(() -> new TestNgOperation().fromProject(new Project()) .suites("src/test/resources/testng2.xml") .execute()) - .doesNotThrowAnyException(); + .as("suite 2").doesNotThrowAnyException(); assertThatCode(() -> new TestNgOperation().fromProject(new Project()) .suites("src/test/resources/testng3.xml") .log(2) .execute()) - .doesNotThrowAnyException(); + .as("suite 3").doesNotThrowAnyException(); + + assertThatCode(() -> + new TestNgOperation().fromProject(new Project()) + .suites("src/test/resources/testng3.xml") + .testClasspath("lib/test/*", "build/main", "build/test") + .log(2) + .execute()) + .as("with run classpath").doesNotThrowAnyException(); } @Test diff --git a/src/test/java/rife/bld/extension/TestNgSimpleTest.java b/src/test/java/rife/bld/extension/TestNgSimpleTest.java index 59f472d..6c091ec 100644 --- a/src/test/java/rife/bld/extension/TestNgSimpleTest.java +++ b/src/test/java/rife/bld/extension/TestNgSimpleTest.java @@ -30,13 +30,13 @@ class TestNgSimpleTest { new TestNgSimpleTest().verifyHello(); } - @Test - void verifyHello() { - Assert.assertTrue(true); - } - @Test void testFail() { Assert.fail("failed"); } + + @Test + void verifyHello() { + Assert.assertTrue(true); + } } diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml index 0924379..41fd8ae 100644 --- a/src/test/resources/testng.xml +++ b/src/test/resources/testng.xml @@ -1,8 +1,8 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/src/test/resources/testng2.xml b/src/test/resources/testng2.xml index 51b74ef..01168b7 100644 --- a/src/test/resources/testng2.xml +++ b/src/test/resources/testng2.xml @@ -1,10 +1,10 @@ - - + + - + diff --git a/src/test/resources/testng3.xml b/src/test/resources/testng3.xml index bb9772f..baa78e5 100644 --- a/src/test/resources/testng3.xml +++ b/src/test/resources/testng3.xml @@ -1,10 +1,10 @@ - - + + - +