Added log/verbose command line options and related tests
This commit is contained in:
parent
1bb359dcc6
commit
a84a6fe9e2
4 changed files with 122 additions and 27 deletions
|
@ -65,8 +65,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
|
||||
/**
|
||||
* This sets the default maximum number of threads to use for data providers when running tests in parallel.
|
||||
* It will only take effect if the parallel mode has been selected (for example, with the parallel option).
|
||||
* This can be overridden in the suite definition.
|
||||
* It will only take effect if the parallel mode has been selected (for example,with the
|
||||
* {@link #parallel(Parallel) parallel} option). This can be overridden in the suite definition.
|
||||
*/
|
||||
public TestNgOperation dataProviderThreadCount(int count) {
|
||||
options.put("-dataproviderthreadcount", String.valueOf(count));
|
||||
|
@ -98,7 +98,7 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Part of the {@link #execute} operation, constructs the command list to use for building the process.
|
||||
* Part of the {@link #execute execute} operation, constructs the command list to use for building the process.
|
||||
*/
|
||||
@Override
|
||||
protected List<String> executeConstructProcessCommandList() {
|
||||
|
@ -153,7 +153,7 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Configures a PMD operation from a {@link BaseProject}.
|
||||
* Configures the {@link BaseProject}.
|
||||
*/
|
||||
@Override
|
||||
public TestNgOperation fromProject(BaseProject project) {
|
||||
|
@ -180,7 +180,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* The list of groups you want to run (e.g. "{@code "windows", "linux", "regression}").
|
||||
* The list of groups you want to run.
|
||||
* For example: {@code "windows", "linux", "regression}.
|
||||
*/
|
||||
public TestNgOperation groups(String... group) {
|
||||
options.put("-groups", String.join(",", group));
|
||||
|
@ -188,8 +189,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Ignore missed test names given by '-testnames' and continue to run existing tests, if any.
|
||||
* Default is {@code false}.
|
||||
* Ignore missed test names given by {@link #testNames(String...) testNames} and continue to run existing tests,
|
||||
* if any. Default is {@code false}.
|
||||
*/
|
||||
public TestNgOperation ignoreMissedTestName(Boolean isIgnoreMissedTestNames) {
|
||||
options.put("-ignoreMissedTestNames", String.valueOf(isIgnoreMissedTestNames));
|
||||
|
@ -206,7 +207,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the JUnit mode. Default is {@code false}.
|
||||
* Enables or disables the JUnit mode.
|
||||
* Default is {@code false}.
|
||||
*/
|
||||
public TestNgOperation jUnit(Boolean isJunit) {
|
||||
options.put("-junit", String.valueOf(isJunit));
|
||||
|
@ -223,7 +225,17 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Specifies list of {@code .class} files or list of class names implementing {@code IMethodSelector{}
|
||||
* Set the Level of verbosity.
|
||||
*
|
||||
* @see #verbose(int)
|
||||
*/
|
||||
public TestNgOperation log(int level) {
|
||||
options.put("-log", String.valueOf(level));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the list of {@code .class} files or class names implementing {@code IMethodSelector}.
|
||||
* For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"}
|
||||
*/
|
||||
public TestNgOperation methodSelectors(String... selector) {
|
||||
|
@ -242,7 +254,7 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
|
||||
/**
|
||||
* Mixed mode autodetects the type of current test and run it with appropriate runner.
|
||||
* Default is {@code false}
|
||||
* Default is {@code false}.
|
||||
*/
|
||||
public TestNgOperation mixed(Boolean isMixed) {
|
||||
options.put("-mixed", String.valueOf(isMixed));
|
||||
|
@ -250,7 +262,7 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* The list of {@code .class} files or list of class names implementing {@code ITestRunnerFactory}.
|
||||
* The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}.
|
||||
*/
|
||||
public TestNgOperation objectFactory(String... factory) {
|
||||
options.put("-objectfactory", String.join(",", factory));
|
||||
|
@ -267,10 +279,10 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* The list of packages to include in this test. For example: {@code "com.example", "test.sample.*"}
|
||||
* The list of packages to include in this test.
|
||||
* For example: {@code "com.example", "test.sample.*"}
|
||||
* If the package name ends with .* then subpackages are included too.
|
||||
* Required if no {@link #suites(String...)}
|
||||
* specified.
|
||||
* Required if no {@link #suites(String... suites)} specified.
|
||||
*/
|
||||
public TestNgOperation packages(String... name) {
|
||||
packages.addAll(Arrays.stream(name).toList());
|
||||
|
@ -281,8 +293,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
* If specified, sets the default mechanism used to determine how to use parallel threads when running tests.
|
||||
* If not set, default mechanism is not to use parallel threads at all.
|
||||
* This can be overridden in the suite definition.
|
||||
*
|
||||
* @see Parallel
|
||||
*/
|
||||
|
||||
public TestNgOperation parallel(Parallel mechanism) {
|
||||
options.put("-parallel", mechanism.name().toLowerCase(Locale.getDefault()));
|
||||
return this;
|
||||
|
@ -297,7 +310,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Should TestNG consider failures in Data Providers as test failures. Default is {@code false}.
|
||||
* Should TestNG consider failures in Data Providers as test failures.
|
||||
* Default is {@code false}.
|
||||
*/
|
||||
public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropagateDataProviderFailure) {
|
||||
options.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure));
|
||||
|
@ -323,7 +337,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* List fully qualified class names of listeners that should be skipped from being wired in via Service Loaders.
|
||||
* Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via
|
||||
* Service Loaders.
|
||||
*/
|
||||
public TestNgOperation spiListenersToSkip(String... listenerToSkip) {
|
||||
options.put("-spilistenerstoskip", String.join(",", listenerToSkip));
|
||||
|
@ -331,7 +346,7 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* This specifies the default name of test suite, if not specified in suite definition file or source code.
|
||||
* This specifies the default name of the test suite, if not specified in the suite definition file or source code.
|
||||
* This option is ignored if the {@code suite.xml} file or the source code specifies a different suite name.
|
||||
*/
|
||||
public TestNgOperation suiteName(String name) {
|
||||
|
@ -349,13 +364,16 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Specifies the suites to run. For example: {@code "testng.xml", "testng2.xml"}
|
||||
* Specifies the suites to run. For example: {@code "testng.xml", "testng2.xml"}.
|
||||
*/
|
||||
public TestNgOperation suites(String... suite) {
|
||||
suites.addAll(Arrays.stream(suite).toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a test file and delete it on exit.
|
||||
*/
|
||||
private File tempFile() throws IOException {
|
||||
var temp = File.createTempFile("testng", ".xml");
|
||||
temp.deleteOnExit();
|
||||
|
@ -363,7 +381,7 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* A list of class files separated by commas (e.g. {@code "org.foo.Test1","org.foo.test2"}).
|
||||
* Specifies the list of class files. For example: {@code "org.foo.Test1","org.foo.test2"}.
|
||||
*/
|
||||
public TestNgOperation testClass(String... aClass) {
|
||||
options.put("-testclass", String.join(",", aClass));
|
||||
|
@ -371,8 +389,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Specifies a jar file that contains test classes. If a 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 classes.
|
||||
* 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
|
||||
* classes.
|
||||
*/
|
||||
public TestNgOperation testJar(String jar) {
|
||||
options.put("-testjar", jar);
|
||||
|
@ -380,8 +399,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* This specifies the default name of test, if not specified in suite definition file or source code.
|
||||
* This option is ignored if the suite.xml file or the source code specifies a different test name.
|
||||
* This specifies the default name of test, if not specified in the suite definition file or source code.
|
||||
* This option is ignored if the {@code suite.xml} file or the source code specifies a different test name.
|
||||
*/
|
||||
public TestNgOperation testName(String name) {
|
||||
options.put("-testname", '"' + name + '"');
|
||||
|
@ -406,8 +425,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
|
||||
/**
|
||||
* This sets the default maximum number of threads to use for running tests in parallel. It will only take effect
|
||||
* if the parallel mode has been selected (for example, with the -parallel option). This can be overridden in the
|
||||
* suite definition.
|
||||
* if the parallel mode has been selected (for example, with the {@link #parallel(Parallel) parallel} option).
|
||||
* This can be overridden in the suite definition.
|
||||
*/
|
||||
public TestNgOperation threadCount(int count) {
|
||||
options.put("-threadcount", String.valueOf(count));
|
||||
|
@ -430,6 +449,16 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Level of verbosity.
|
||||
*
|
||||
* @see #log(int)
|
||||
*/
|
||||
public TestNgOperation verbose(int level) {
|
||||
options.put("-verbose", String.valueOf(level));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This attribute should contain the path to a valid XML file inside the test jar
|
||||
* (e.g. {@code "resources/testng.xml"}). The default is {@code testng.xml}, which means a file called
|
||||
|
|
|
@ -96,6 +96,13 @@ class TestNgOperationTest {
|
|||
.suites("src/test/resources/testng2.xml")
|
||||
.execute())
|
||||
.doesNotThrowAnyException();
|
||||
|
||||
assertThatCode(() ->
|
||||
new TestNgOperation().fromProject(new Project())
|
||||
.suites("src/test/resources/testng3.xml")
|
||||
.log(2)
|
||||
.execute())
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -302,6 +309,15 @@ class TestNgOperationTest {
|
|||
assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVerbose() {
|
||||
var op = new TestNgOperation().log(1);
|
||||
assertThat(op.options.get("-log")).isEqualTo("1");
|
||||
|
||||
op = new TestNgOperation().verbose(1);
|
||||
assertThat(op.options.get("-verbose")).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testXmlPathInJar() {
|
||||
var op = new TestNgOperation().xmlPathInJar(FOO);
|
||||
|
|
37
src/test/java/rife/bld/extension/TestNgSimple2Test.java
Normal file
37
src/test/java/rife/bld/extension/TestNgSimple2Test.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Implements the TestNgSimpleTest class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
class TestNgSimple2Test {
|
||||
public static void main(String[] args) {
|
||||
new TestNgSimple2Test().verifyHello();
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyHello() {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
13
src/test/resources/testng3.xml
Normal file
13
src/test/resources/testng3.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
|
||||
<suite name="test suite 3" >
|
||||
<test name="test 2 classes" >
|
||||
<classes>
|
||||
<class name="rife.bld.extension.TestNgSimpleTest">
|
||||
<methods>
|
||||
<exclude name="testFail" />
|
||||
</methods>
|
||||
</class>
|
||||
<class name="rife.bld.extension.TestNgSimple2Test"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
Loading…
Add table
Add a link
Reference in a new issue