Added option to set the tests classpath
This commit is contained in:
parent
89a662a1c4
commit
65b9ea190b
8 changed files with 55 additions and 25 deletions
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
|
@ -4,6 +4,7 @@
|
||||||
<pattern value="rife.bld.extension.TestNgOperationBuild" method="pmd" />
|
<pattern value="rife.bld.extension.TestNgOperationBuild" method="pmd" />
|
||||||
<pattern value="rife.bld.extension.TestNgOperationBuild" />
|
<pattern value="rife.bld.extension.TestNgOperationBuild" />
|
||||||
<pattern value="rife.bld.extension.TestNGSimpleTest" method="testFail" />
|
<pattern value="rife.bld.extension.TestNGSimpleTest" method="testFail" />
|
||||||
|
<pattern value="rife.bld.extension.TestNgSimpleTest" method="testFail" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PDMPlugin">
|
<component name="PDMPlugin">
|
||||||
<option name="customRuleSets">
|
<option name="customRuleSets">
|
||||||
|
|
|
@ -26,7 +26,8 @@ import java.util.List;
|
||||||
|
|
||||||
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
|
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
|
||||||
import static rife.bld.dependencies.Repository.RIFE2_RELEASES;
|
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;
|
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
|
||||||
|
|
||||||
public class TestNgOperationBuild extends Project {
|
public class TestNgOperationBuild extends Project {
|
||||||
|
|
|
@ -52,6 +52,10 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
||||||
* The suites to run.
|
* The suites to run.
|
||||||
*/
|
*/
|
||||||
protected final List<String> suites = new ArrayList<>();
|
protected final List<String> suites = new ArrayList<>();
|
||||||
|
/**
|
||||||
|
* The classpath entries used for running tests.
|
||||||
|
*/
|
||||||
|
protected final List<String> testClasspath = new ArrayList<>();
|
||||||
private final List<String> args = new ArrayList<>();
|
private final List<String> args = new ArrayList<>();
|
||||||
private BaseProject project;
|
private BaseProject project;
|
||||||
|
|
||||||
|
@ -118,9 +122,15 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
||||||
|
|
||||||
args.clear();
|
args.clear();
|
||||||
args.add(javaTool());
|
args.add(javaTool());
|
||||||
|
|
||||||
args.add("-cp");
|
args.add("-cp");
|
||||||
|
if (testClasspath.isEmpty()) {
|
||||||
args.add(String.format("%s:%s:%s", Path.of(project.libTestDirectory().getPath(), "*"),
|
args.add(String.format("%s:%s:%s", Path.of(project.libTestDirectory().getPath(), "*"),
|
||||||
project.buildMainDirectory(), project.buildTestDirectory()));
|
project.buildMainDirectory(), project.buildTestDirectory()));
|
||||||
|
} else {
|
||||||
|
args.add(String.join(":", testClasspath));
|
||||||
|
}
|
||||||
|
|
||||||
args.add("org.testng.TestNG");
|
args.add("org.testng.TestNG");
|
||||||
|
|
||||||
options.forEach((k, v) -> {
|
options.forEach((k, v) -> {
|
||||||
|
@ -406,6 +416,14 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
||||||
return this;
|
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
|
* 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
|
* jar file, it will be used, otherwise, all the test classes found in this jar file will be considered test
|
||||||
|
|
|
@ -77,32 +77,42 @@ class TestNgOperationTest {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.testClass("rife.bld.extension.TestNgSimpleTest")
|
.testClass("rife.bld.extension.TestNgSimpleTest")
|
||||||
.execute()).isInstanceOf(ExitStatusException.class);
|
.execute())
|
||||||
|
.as("with testClass").isInstanceOf(ExitStatusException.class);
|
||||||
|
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.suites("src/test/resources/testng.xml")
|
.suites("src/test/resources/testng.xml")
|
||||||
.execute()).isInstanceOf(ExitStatusException.class);
|
.execute())
|
||||||
|
.as("with suites").isInstanceOf(ExitStatusException.class);
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.testClass("rife.bld.extension.TestNgSimpleTest")
|
.testClass("rife.bld.extension.TestNgSimpleTest")
|
||||||
.methods("rife.bld.extension.TestNgSimpleTest.verifyHello")
|
.methods("rife.bld.extension.TestNgSimpleTest.verifyHello")
|
||||||
.execute())
|
.execute())
|
||||||
.doesNotThrowAnyException();
|
.as("with methods").doesNotThrowAnyException();
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.suites("src/test/resources/testng2.xml")
|
.suites("src/test/resources/testng2.xml")
|
||||||
.execute())
|
.execute())
|
||||||
.doesNotThrowAnyException();
|
.as("suite 2").doesNotThrowAnyException();
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.suites("src/test/resources/testng3.xml")
|
.suites("src/test/resources/testng3.xml")
|
||||||
.log(2)
|
.log(2)
|
||||||
.execute())
|
.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
|
@Test
|
||||||
|
|
|
@ -30,13 +30,13 @@ class TestNgSimpleTest {
|
||||||
new TestNgSimpleTest().verifyHello();
|
new TestNgSimpleTest().verifyHello();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void verifyHello() {
|
|
||||||
Assert.assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFail() {
|
void testFail() {
|
||||||
Assert.fail("failed");
|
Assert.fail("failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void verifyHello() {
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<suite name="test suite 1" verbose="2" >
|
<suite name="test suite 1" verbose="2">
|
||||||
<test name="simple test" >
|
<test name="simple test">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="rife.bld.extension.TestNgSimpleTest" />
|
<class name="rife.bld.extension.TestNgSimpleTest"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
|
@ -1,10 +1,10 @@
|
||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
<suite name="test suite 2" verbose="1" >
|
<suite name="test suite 2" verbose="1">
|
||||||
<test name="exclude fail" >
|
<test name="exclude fail">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="rife.bld.extension.TestNgSimpleTest">
|
<class name="rife.bld.extension.TestNgSimpleTest">
|
||||||
<methods>
|
<methods>
|
||||||
<exclude name="testFail" />
|
<exclude name="testFail"/>
|
||||||
</methods>
|
</methods>
|
||||||
</class>
|
</class>
|
||||||
</classes>
|
</classes>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
|
||||||
<suite name="test suite 3" >
|
<suite name="test suite 3">
|
||||||
<test name="test 2 classes" >
|
<test name="test 2 classes">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="rife.bld.extension.TestNgSimpleTest">
|
<class name="rife.bld.extension.TestNgSimpleTest">
|
||||||
<methods>
|
<methods>
|
||||||
<exclude name="testFail" />
|
<exclude name="testFail"/>
|
||||||
</methods>
|
</methods>
|
||||||
</class>
|
</class>
|
||||||
<class name="rife.bld.extension.TestNgSimple2Test"/>
|
<class name="rife.bld.extension.TestNgSimple2Test"/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue