Added array for the methods argument
This commit is contained in:
parent
8db60b473c
commit
7aedfc790e
3 changed files with 31 additions and 9 deletions
|
@ -41,9 +41,9 @@ import java.util.stream.Collectors;
|
|||
public class TestNgOperation extends TestOperation<TestNgOperation, List<String>> {
|
||||
private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName());
|
||||
/**
|
||||
* The classpath entries used for running tests.
|
||||
* The methods to run.
|
||||
*/
|
||||
private final Set<String> testClasspath_ = new HashSet<>();
|
||||
private final Set<String> methods_ = new HashSet<>();
|
||||
/**
|
||||
* The run options.
|
||||
*/
|
||||
|
@ -56,6 +56,10 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
|
|||
* The suites to run.
|
||||
*/
|
||||
private final Set<String> suites_ = new HashSet<>();
|
||||
/**
|
||||
* The classpath entries used for running tests.
|
||||
*/
|
||||
private final Set<String> testClasspath_ = new HashSet<>();
|
||||
private BaseProject project_;
|
||||
|
||||
/**
|
||||
|
@ -202,13 +206,19 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
|
|||
}
|
||||
}
|
||||
|
||||
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<TestNgOperation, List<String>
|
|||
* @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<TestNgOperation, List<String>
|
|||
* @see #methods(String...) #methods(String...)
|
||||
*/
|
||||
public TestNgOperation methods(Collection<String> 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<String> methods() {
|
||||
return methods_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixed mode autodetects the type of current test and run it with appropriate runner.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
<test name="simple test">
|
||||
<classes>
|
||||
<class name="rife.bld.extension.TestNgExample"/>
|
||||
<methods>
|
||||
<exclude name="foo"/>
|
||||
</methods>
|
||||
</class>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
Loading…
Add table
Add a link
Reference in a new issue