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>> {
|
public class TestNgOperation extends TestOperation<TestNgOperation, List<String>> {
|
||||||
private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName());
|
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.
|
* The run options.
|
||||||
*/
|
*/
|
||||||
|
@ -56,6 +56,10 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
|
||||||
* The suites to run.
|
* The suites to run.
|
||||||
*/
|
*/
|
||||||
private final Set<String> suites_ = new HashSet<>();
|
private final Set<String> suites_ = new HashSet<>();
|
||||||
|
/**
|
||||||
|
* The classpath entries used for running tests.
|
||||||
|
*/
|
||||||
|
private final Set<String> testClasspath_ = new HashSet<>();
|
||||||
private BaseProject project_;
|
private BaseProject project_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,14 +206,20 @@ 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()) {
|
if (LOGGER.isLoggable(Level.FINE) && !silent()) {
|
||||||
LOGGER.fine(String.join(" ", args));
|
LOGGER.fine(String.join(" ", args));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
LOGGER.info(String.format("Report will be saved in file://%s",
|
LOGGER.info(String.format("Report will be saved in file://%s",
|
||||||
new File(options_.get("-d")).toURI().getPath()));
|
new File(options_.get("-d")).toURI().getPath()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
@ -441,7 +451,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
|
||||||
* @see #methods(Collection) #methods(Collection)
|
* @see #methods(Collection) #methods(Collection)
|
||||||
*/
|
*/
|
||||||
public TestNgOperation methods(String... method) {
|
public TestNgOperation methods(String... method) {
|
||||||
options_.put("-methods", String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList()));
|
methods_.addAll(List.of(method));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,10 +465,19 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
|
||||||
* @see #methods(String...) #methods(String...)
|
* @see #methods(String...) #methods(String...)
|
||||||
*/
|
*/
|
||||||
public TestNgOperation methods(Collection<String> method) {
|
public TestNgOperation methods(Collection<String> method) {
|
||||||
options_.put("-methods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
|
methods_.addAll(method);
|
||||||
return this;
|
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.
|
* Mixed mode autodetects the type of current test and run it with appropriate runner.
|
||||||
*
|
*
|
||||||
|
|
|
@ -169,10 +169,9 @@ class TestNgOperationTest {
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.testClass("rife.bld.extension.TestNgExampleTest")
|
.methods("rife.bld.extension.TestNgExampleTest.foo")
|
||||||
.methods("rife.bld.extension.TestNgExampleTest.verifyHello")
|
|
||||||
.execute())
|
.execute())
|
||||||
.as("with methods").doesNotThrowAnyException();
|
.as("with methods").isInstanceOf(ExitStatusException.class);
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
|
@ -295,10 +294,10 @@ class TestNgOperationTest {
|
||||||
@Test
|
@Test
|
||||||
void testMethods() {
|
void testMethods() {
|
||||||
var op = new TestNgOperation().methods(FOO, BAR);
|
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));
|
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
|
@Test
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
<test name="simple test">
|
<test name="simple test">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="rife.bld.extension.TestNgExample"/>
|
<class name="rife.bld.extension.TestNgExample"/>
|
||||||
|
<methods>
|
||||||
|
<exclude name="foo"/>
|
||||||
|
</methods>
|
||||||
|
</class>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
Loading…
Add table
Add a link
Reference in a new issue