diff --git a/src/main/java/rife/bld/extension/TestNgOperation.java b/src/main/java/rife/bld/extension/TestNgOperation.java index 4ce9979..2b67f0e 100644 --- a/src/main/java/rife/bld/extension/TestNgOperation.java +++ b/src/main/java/rife/bld/extension/TestNgOperation.java @@ -41,9 +41,9 @@ import java.util.stream.Collectors; public class TestNgOperation extends TestOperation> { private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName()); /** - * The classpath entries used for running tests. + * The methods to run. */ - private final Set testClasspath_ = new HashSet<>(); + private final Set methods_ = new HashSet<>(); /** * The run options. */ @@ -56,6 +56,10 @@ public class TestNgOperation extends TestOperation * The suites to run. */ private final Set suites_ = new HashSet<>(); + /** + * The classpath entries used for running tests. + */ + private final Set testClasspath_ = new HashSet<>(); private BaseProject project_; /** @@ -202,13 +206,19 @@ public class TestNgOperation extends TestOperation } } + if (!methods_.isEmpty()) { + args.add("-methods"); + args.add(String.join(",", methods_)); + } if (LOGGER.isLoggable(Level.FINE) && !silent()) { LOGGER.fine(String.join(" ", args)); } + if (LOGGER.isLoggable(Level.INFO) && !silent()) { LOGGER.info(String.format("Report will be saved in file://%s", new File(options_.get("-d")).toURI().getPath())); + } } return args; @@ -441,7 +451,7 @@ public class TestNgOperation extends TestOperation * @see #methods(Collection) #methods(Collection) */ public TestNgOperation methods(String... method) { - options_.put("-methods", String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList())); + methods_.addAll(List.of(method)); return this; } @@ -455,10 +465,19 @@ public class TestNgOperation extends TestOperation * @see #methods(String...) #methods(String...) */ public TestNgOperation methods(Collection method) { - options_.put("-methods", String.join(",", method.stream().filter(this::isNotBlank).toList())); + methods_.addAll(method); return this; } + /** + * Returns the methods to run. + * + * @return the set of methods + */ + public Set methods() { + return methods_; + } + /** * Mixed mode autodetects the type of current test and run it with appropriate runner. * diff --git a/src/test/java/rife/bld/extension/TestNgOperationTest.java b/src/test/java/rife/bld/extension/TestNgOperationTest.java index c6c7bc2..83b1f80 100644 --- a/src/test/java/rife/bld/extension/TestNgOperationTest.java +++ b/src/test/java/rife/bld/extension/TestNgOperationTest.java @@ -169,10 +169,9 @@ class TestNgOperationTest { assertThatCode(() -> new TestNgOperation().fromProject(new Project()) - .testClass("rife.bld.extension.TestNgExampleTest") - .methods("rife.bld.extension.TestNgExampleTest.verifyHello") + .methods("rife.bld.extension.TestNgExampleTest.foo") .execute()) - .as("with methods").doesNotThrowAnyException(); + .as("with methods").isInstanceOf(ExitStatusException.class); assertThatCode(() -> new TestNgOperation().fromProject(new Project()) @@ -295,10 +294,10 @@ class TestNgOperationTest { @Test void testMethods() { var op = new TestNgOperation().methods(FOO, BAR); - assertThat(op.options().get("-methods")).isEqualTo(String.format("%s,%s", FOO, BAR)); + assertThat(op.methods()).containsExactly(BAR, FOO); new TestNgOperation().methods(List.of(FOO, BAR)); - assertThat(op.options().get("-methods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); + assertThat(op.methods()).containsExactly(BAR, FOO); } @Test diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml index 8ad378e..ef68357 100644 --- a/src/test/resources/testng.xml +++ b/src/test/resources/testng.xml @@ -3,6 +3,10 @@ + + + + \ No newline at end of file