* @return this operation instance
*/
public TestNgOperation mixed(Boolean isMixed) {
- options.put("-mixed", String.valueOf(isMixed));
- return this;
- }
-
- /**
- * Fully qualified class name that implements {@code org.testng.ITestObjectFactory} which can be used to create
- * test class and listener instances.
- *
- * @param objectFactory the object factory
- * @return this operation instance
- */
- public TestNgOperation objectFactory(String objectFactory) {
- options.put("-objectfactory", objectFactory);
+ options_.put("-mixed", String.valueOf(isMixed));
return this;
}
/**
* The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}.
+ *
+ * A fully qualified class name that implements {@code org.testng.ITestObjectFactory} which can be used to create
+ * test class and listener instances.
*
- * @param factory one or more factories
+ * @param factory one or more factory
* @return this operation instance
* @see #objectFactory(Collection) #objectFactory(Collection)
*/
public TestNgOperation objectFactory(String... factory) {
- options.put("-objectfactory", String.join(",", Arrays.stream(factory).filter(this::isNotBlank).toList()));
- return this;
+ return objectFactory(List.of(factory));
}
/**
* The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}.
+ *
+ * A fully qualified class name that implements {@code org.testng.ITestObjectFactory} which can be used to create
+ * test class and listener instances.
*
* @param factory the list of factories
* @return this operation instance
* @see #objectFactory(String...) #objectFactory(String...)
*/
public TestNgOperation objectFactory(Collection factory) {
- options.put("-objectfactory", String.join(",", factory.stream().filter(this::isNotBlank).toList()));
+ options_.put("-objectfactory", String.join(",", factory.stream().filter(this::isNotBlank).toList()));
return this;
}
+ /**
+ * Returns the run options.
+ *
+ * @return the map of run options
+ */
+ public Map options() {
+ return options_;
+ }
+
/**
* The list of fully qualified class names of listeners that should be skipped from being wired in via
* Service Loaders.
@@ -498,9 +580,7 @@ public class TestNgOperation extends TestOperation
* @see #overrideIncludedMethods(Collection) #overrideIncludedMethods(Collection)
*/
public TestNgOperation overrideIncludedMethods(String... method) {
- options.put("-overrideincludedmethods",
- String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList()));
- return this;
+ return overrideIncludedMethods(List.of(method));
}
/**
@@ -512,7 +592,7 @@ public class TestNgOperation extends TestOperation
* @see #overrideIncludedMethods(String...) #overrideIncludedMethods(String...)
*/
public TestNgOperation overrideIncludedMethods(Collection method) {
- options.put("-overrideincludedmethods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
+ options_.put("-overrideincludedmethods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
return this;
}
@@ -528,8 +608,7 @@ public class TestNgOperation extends TestOperation
* @see #packages(Collection) #packages(Collection)
*/
public TestNgOperation packages(String... name) {
- packages.addAll(Arrays.stream(name).filter(this::isNotBlank).toList());
- return this;
+ return packages(List.of(name));
}
/**
@@ -544,10 +623,19 @@ public class TestNgOperation extends TestOperation
* @see #packages(String...) #packages(String...)
*/
public TestNgOperation packages(Collection name) {
- packages.addAll(name.stream().filter(this::isNotBlank).toList());
+ packages_.addAll(name.stream().filter(this::isNotBlank).toList());
return this;
}
+ /**
+ * Returns the suite packages to run.
+ *
+ * @return the set of packages
+ */
+ public Set packages() {
+ return packages_;
+ }
+
/**
* 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.
@@ -558,7 +646,7 @@ public class TestNgOperation extends TestOperation
* @see Parallel
*/
public TestNgOperation parallel(Parallel mechanism) {
- options.put("-parallel", mechanism.name().toLowerCase(Locale.getDefault()));
+ options_.put("-parallel", mechanism.name().toLowerCase(Locale.getDefault()));
return this;
}
@@ -570,7 +658,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation port(int port) {
if (port >= 1) {
- options.put("-port", String.valueOf(port));
+ options_.put("-port", String.valueOf(port));
}
return this;
}
@@ -584,7 +672,7 @@ public class TestNgOperation extends TestOperation
* @return this operation instance
*/
public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropagateDataProviderFailure) {
- options.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure));
+ options_.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure));
return this;
}
@@ -596,7 +684,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation reporter(String reporter) {
if (isNotBlank(reporter)) {
- options.put("-reporter", reporter);
+ options_.put("-reporter", reporter);
}
return this;
}
@@ -609,7 +697,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolForDataProviders) {
if (shareThreadPoolForDataProviders) {
- options.put("-shareThreadPoolForDataProviders", String.valueOf(shareThreadPoolForDataProviders));
+ options_.put("-shareThreadPoolForDataProviders", "true");
}
return this;
}
@@ -621,10 +709,49 @@ public class TestNgOperation extends TestOperation
*
* @param directory one or more directories
* @return this operation instance
- * @see #sourceDir(String...) #sourceDir(String...)
+ * @see #sourceDir(Collection)
*/
public TestNgOperation sourceDir(String... directory) {
- options.put("-sourcedir", String.join(";", Arrays.stream(directory).filter(this::isNotBlank).toList()));
+ return sourceDir(List.of(directory));
+ }
+
+ /**
+ * The directories where your javadoc annotated test sources are. This option is only necessary
+ * if you are using javadoc type annotations. (e.g. {@code "src/test"} or
+ * {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
+ *
+ * @param directory one or more directories
+ * @return this operation instance
+ * @see #sourceDirFiles(Collection)
+ */
+ public TestNgOperation sourceDir(File... directory) {
+ return sourceDirFiles(List.of(directory));
+ }
+
+ /**
+ * The directories where your javadoc annotated test sources are. This option is only necessary
+ * if you are using javadoc type annotations. (e.g. {@code "src/test"} or
+ * {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
+ *
+ * @param directory one or more directories
+ * @return this operation instance
+ * @see #sourceDirPaths(Collection)
+ */
+ public TestNgOperation sourceDir(Path... directory) {
+ return sourceDirPaths(List.of(directory));
+ }
+
+ /**
+ * The directories where your javadoc annotated test sources are. This option is only necessary
+ * if you are using javadoc type annotations. (e.g. {@code "src/test"} or
+ * {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
+ *
+ * @param directory the list of directories
+ * @return this operation instance
+ * @see #sourceDir(String...)
+ */
+ public TestNgOperation sourceDir(Collection directory) {
+ options_.put("-sourcedir", String.join(";", directory.stream().filter(this::isNotBlank).toList()));
return this;
}
@@ -635,11 +762,23 @@ public class TestNgOperation extends TestOperation
*
* @param directory the list of directories
* @return this operation instance
- * @see #sourceDir(String...) #sourceDir(String...)
+ * @see #sourceDir(File...)
*/
- public TestNgOperation sourceDir(Collection directory) {
- options.put("-sourcedir", String.join(";", directory.stream().filter(this::isNotBlank).toList()));
- return this;
+ public TestNgOperation sourceDirFiles(Collection directory) {
+ return sourceDir(directory.stream().map(File::getAbsolutePath).toList());
+ }
+
+ /**
+ * The directories where your javadoc annotated test sources are. This option is only necessary
+ * if you are using javadoc type annotations. (e.g. {@code "src/test"} or
+ * {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
+ *
+ * @param directory the list of directories
+ * @return this operation instance
+ * @see #sourceDir(Path...)
+ */
+ public TestNgOperation sourceDirPaths(Collection directory) {
+ return sourceDirFiles(directory.stream().map(Path::toFile).toList());
}
/**
@@ -651,9 +790,7 @@ public class TestNgOperation extends TestOperation
* @see #spiListenersToSkip(Collection) #spiListenersToSkip(Collection)
*/
public TestNgOperation spiListenersToSkip(String... listenerToSkip) {
- options.put("-spilistenerstoskip",
- String.join(",", Arrays.stream(listenerToSkip).filter(this::isNotBlank).toList()));
- return this;
+ return spiListenersToSkip(List.of(listenerToSkip));
}
/**
@@ -665,7 +802,7 @@ public class TestNgOperation extends TestOperation
* @see #spiListenersToSkip(String...) #spiListenersToSkip(String...)
*/
public TestNgOperation spiListenersToSkip(Collection listenerToSkip) {
- options.put("-spilistenerstoskip",
+ options_.put("-spilistenerstoskip",
String.join(",", listenerToSkip.stream().filter(this::isNotBlank).toList()));
return this;
}
@@ -679,7 +816,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation suiteName(String name) {
if (isNotBlank(name)) {
- options.put("-suitename", '"' + name + '"');
+ options_.put("-suitename", '"' + name + '"');
}
return this;
}
@@ -693,7 +830,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation suiteThreadPoolSize(int poolSize) {
if (poolSize >= 0) {
- options.put("-suitethreadpoolsize", String.valueOf(poolSize));
+ options_.put("-suitethreadpoolsize", String.valueOf(poolSize));
}
return this;
}
@@ -708,8 +845,7 @@ public class TestNgOperation extends TestOperation
* @see #suites(Collection) #suites(Collection)
*/
public TestNgOperation suites(String... suite) {
- suites.addAll(Arrays.stream(suite).filter(this::isNotBlank).toList());
- return this;
+ return suites(List.of(suite));
}
/**
@@ -722,10 +858,19 @@ public class TestNgOperation extends TestOperation
* @see #suites(String...) #suites(String...)
*/
public TestNgOperation suites(Collection suite) {
- suites.addAll(suite.stream().filter(this::isNotBlank).toList());
+ suites_.addAll(suite.stream().filter(this::isNotBlank).toList());
return this;
}
+ /**
+ * Returns the suites to run.
+ *
+ * @return the set of suites
+ */
+ public Set suites() {
+ return suites_;
+ }
+
/**
* Create a test file and delete it on exit.
*
@@ -747,8 +892,7 @@ public class TestNgOperation extends TestOperation
* @see #testClass(Collection) #testClass(Collection)
*/
public TestNgOperation testClass(String... aClass) {
- options.put("-testclass", String.join(",", Arrays.stream(aClass).filter(this::isNotBlank).toList()));
- return this;
+ return testClass(List.of(aClass));
}
/**
@@ -761,7 +905,7 @@ public class TestNgOperation extends TestOperation
* @see #testClass(String...) #testClass(String...)
*/
public TestNgOperation testClass(Collection aClass) {
- options.put("-testclass", String.join(",", aClass.stream().filter(this::isNotBlank).toList()));
+ options_.put("-testclass", String.join(",", aClass.stream().filter(this::isNotBlank).toList()));
return this;
}
@@ -773,8 +917,7 @@ public class TestNgOperation extends TestOperation
* @see #testClasspath(String...) #testClasspath(String...)
*/
public TestNgOperation testClasspath(String... entry) {
- testClasspath.addAll(Arrays.stream(entry).filter(this::isNotBlank).toList());
- return this;
+ return testClasspath(List.of(entry));
}
/**
@@ -785,10 +928,19 @@ public class TestNgOperation extends TestOperation
* @see #testClasspath(String...) #testClasspath(String...)
*/
public TestNgOperation testClasspath(Collection entry) {
- testClasspath.addAll(entry.stream().filter(this::isNotBlank).toList());
+ testClasspath_.addAll(entry.stream().filter(this::isNotBlank).toList());
return this;
}
+ /**
+ * Returns the classpath entries used for running tests.
+ *
+ * @return the set of test classpath
+ */
+ public Set testClasspath() {
+ return testClasspath_;
+ }
+
/**
* 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
@@ -799,7 +951,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation testJar(String jar) {
if (isNotBlank(jar)) {
- options.put("-testjar", jar);
+ options_.put("-testjar", jar);
}
return this;
}
@@ -813,7 +965,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation testName(String name) {
if (isNotBlank(name)) {
- options.put("-testname", '"' + name + '"');
+ options_.put("-testname", '"' + name + '"');
}
return this;
}
@@ -826,9 +978,7 @@ public class TestNgOperation extends TestOperation
* @see #testNames(Collection) #testNames(Collection)
*/
public TestNgOperation testNames(String... name) {
- options.put("-testnames",
- Arrays.stream(name).filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(",")));
- return this;
+ return testNames(List.of(name));
}
/**
@@ -839,7 +989,7 @@ public class TestNgOperation extends TestOperation
* @see #testName(String) #testName(String)
*/
public TestNgOperation testNames(Collection name) {
- options.put("-testnames",
+ options_.put("-testnames",
name.stream().filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(",")));
return this;
}
@@ -852,7 +1002,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation testRunFactory(String factory) {
if (isNotBlank(factory)) {
- options.put("-testrunfactory", factory);
+ options_.put("-testrunfactory", factory);
}
return this;
}
@@ -867,7 +1017,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation threadCount(int count) {
if (count >= 0) {
- options.put("-threadcount", String.valueOf(count));
+ options_.put("-threadcount", String.valueOf(count));
}
return this;
}
@@ -880,7 +1030,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation threadPoolFactoryClass(String factoryClass) {
if (isNotBlank(factoryClass)) {
- options.put("-threadpoolfactoryclass", factoryClass);
+ options_.put("-threadpoolfactoryclass", factoryClass);
}
return this;
}
@@ -894,7 +1044,7 @@ public class TestNgOperation extends TestOperation
* @return this operation instance
*/
public TestNgOperation useDefaultListeners(Boolean isDefaultListener) {
- options.put("-usedefaultlisteners", String.valueOf(isDefaultListener));
+ options_.put("-usedefaultlisteners", String.valueOf(isDefaultListener));
return this;
}
@@ -906,7 +1056,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation useGlobalThreadPool(boolean useGlobalThreadPool) {
if (useGlobalThreadPool) {
- options.put("-useGlobalThreadPool", String.valueOf(useGlobalThreadPool));
+ options_.put("-useGlobalThreadPool", "true");
}
return this;
}
@@ -920,7 +1070,7 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation verbose(int level) {
if (level >= 0) {
- options.put("-verbose", String.valueOf(level));
+ options_.put("-verbose", String.valueOf(level));
}
return this;
}
@@ -929,11 +1079,11 @@ public class TestNgOperation extends TestOperation
var temp = tempFile();
try (var bufWriter = Files.newBufferedWriter(Paths.get(temp.getPath()))) {
bufWriter.write("" +
- "" +
- "" +
- "" +
- "");
- for (var p : packages) {
+ "" +
+ "" +
+ "" +
+ "");
+ for (var p : packages_) {
bufWriter.write(String.format("", p));
}
bufWriter.write("");
@@ -951,11 +1101,35 @@ public class TestNgOperation extends TestOperation
*/
public TestNgOperation xmlPathInJar(String path) {
if (isNotBlank(path)) {
- options.put("-xmlpathinjar", path);
+ options_.put("-xmlpathinjar", path);
}
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
+ * {@code testng.xml} at the root of the jar file. This option will be ignored unless a test jar is specified.
+ *
+ * @param path the path
+ * @return this operation instance
+ */
+ public TestNgOperation xmlPathInJar(File path) {
+ return xmlPathInJar(path.getAbsolutePath());
+ }
+
+ /**
+ * 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
+ * {@code testng.xml} at the root of the jar file. This option will be ignored unless a test jar is specified.
+ *
+ * @param path the path
+ * @return this operation instance
+ */
+ public TestNgOperation xmlPathInJar(Path path) {
+ return xmlPathInJar(path.toFile());
+ }
+
/**
* Parallel Mechanisms
*/
diff --git a/src/test/java/rife/bld/extension/TestNgExample.java b/src/test/java/rife/bld/extension/TestNgExample.java
index c2dc3e0..faa223a 100644
--- a/src/test/java/rife/bld/extension/TestNgExample.java
+++ b/src/test/java/rife/bld/extension/TestNgExample.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 the original author or authors.
+ * Copyright 2023-2025 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.
@@ -22,8 +22,9 @@ package rife.bld.extension;
* @author Erik C. Thauvin
* @since 1.0
*/
-@SuppressWarnings("PMD.TestClassWithoutTestCases")
+@SuppressWarnings({"PMD.TestClassWithoutTestCases", "unused"})
class TestNgExample {
+ @SuppressWarnings("SameReturnValue")
public String getMessage() {
return "Hello World!";
}
diff --git a/src/test/java/rife/bld/extension/TestNgExampleTest.java b/src/test/java/rife/bld/extension/TestNgExampleTest.java
index a2c35b9..6d3c9b0 100644
--- a/src/test/java/rife/bld/extension/TestNgExampleTest.java
+++ b/src/test/java/rife/bld/extension/TestNgExampleTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 the original author or authors.
+ * Copyright 2023-2025 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.
@@ -25,6 +25,7 @@ import org.testng.annotations.Test;
* @author Erik C. Thauvin
* @since 1.0
*/
+@SuppressWarnings("unused")
class TestNgExampleTest {
private final TestNgExample example = new TestNgExample();
diff --git a/src/test/java/rife/bld/extension/TestNgOperationTest.java b/src/test/java/rife/bld/extension/TestNgOperationTest.java
index f216e13..d4f3193 100644
--- a/src/test/java/rife/bld/extension/TestNgOperationTest.java
+++ b/src/test/java/rife/bld/extension/TestNgOperationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 the original author or authors.
+ * Copyright 2023-2025 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.
@@ -16,10 +16,18 @@
package rife.bld.extension;
+import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import rife.bld.Project;
+import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.operations.exceptions.ExitStatusException;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
@@ -38,47 +46,125 @@ class TestNgOperationTest {
@Test
void testAlwaysRunListeners() {
var op = new TestNgOperation().alwaysRunListeners(false);
- assertThat(op.options.get("-alwaysrunlisteners")).isEqualTo("false");
+ assertThat(op.options().get("-alwaysrunlisteners")).isEqualTo("false");
op = new TestNgOperation().alwaysRunListeners(true);
- assertThat(op.options.get("-alwaysrunlisteners")).isEqualTo("true");
+ assertThat(op.options().get("-alwaysrunlisteners")).isEqualTo("true");
+ }
+
+ @Test
+ @EnabledOnOs(OS.LINUX)
+ void testCheckAllParameters() throws IOException {
+ var args = Files.readAllLines(Paths.get("src", "test", "resources", "testng-args.txt"));
+
+ assertThat(args).isNotEmpty();
+
+ var params = new TestNgOperation()
+ .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "examples", "Examples"))
+ .alwaysRunListeners(true)
+ .dataProviderThreadCount(1)
+ .dependencyInjectorFactory("injectorfactory")
+ .directory("dir")
+ .excludeGroups("group")
+ .failWhenEverythingSkipped(true)
+ .failurePolicy(TestNgOperation.FailurePolicy.SKIP)
+ .generateResultsPerSuite(true)
+ .groups("group1", "group2")
+ .ignoreMissedTestName(true)
+ .includeAllDataDrivenTestsWhenSkipping(true)
+ .listener("listener")
+ .listenerComparator("comparator")
+ .listenerFactory("factory")
+ .log(1)
+ .methodSelectors("selector")
+ .methods("methods")
+ .mixed(true)
+ .objectFactory("objectFactory")
+ .overrideIncludedMethods("method")
+ .parallel(TestNgOperation.Parallel.TESTS)
+ .propagateDataProviderFailureAsTestFailure(true)
+ .reporter("reporter")
+ .shareThreadPoolForDataProviders(true)
+ .spiListenersToSkip("listenter")
+ .suiteName("name")
+ .suiteThreadPoolSize(1)
+ .testClass("class")
+ .testJar("jar")
+ .testName("name")
+ .testNames("names")
+ .testRunFactory("runFactory")
+ .threadCount(1)
+ .threadPoolFactoryClass("poolClass")
+ .useDefaultListeners(true)
+ .useGlobalThreadPool(true)
+ .verbose(1)
+ .xmlPathInJar("jarPath")
+ .executeConstructProcessCommandList();
+
+ try (var softly = new AutoCloseableSoftAssertions()) {
+ for (var p : args) {
+ var found = false;
+ for (var a : params) {
+ if (a.startsWith(p)) {
+ found = true;
+ break;
+ }
+ }
+ softly.assertThat(found).as(p + " not found.").isTrue();
+ }
+ }
+
}
@Test
void testClass() {
var op = new TestNgOperation().testClass(FOO, BAR);
- assertThat(op.options.get("-testclass")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(op.options().get("-testclass")).isEqualTo(String.format("%s,%s", FOO, BAR));
new TestNgOperation().testClass(List.of(FOO, BAR));
- assertThat(op.options.get("-testclass")).as("as list")
+ assertThat(op.options().get("-testclass")).as("as list")
.isEqualTo(String.format("%s,%s", FOO, BAR));
}
+ @Test
+ void testClasspath() {
+ var op = new TestNgOperation().testClasspath(FOO, BAR);
+ assertThat(op.testClasspath()).containsExactly(BAR, FOO);
+ }
+
@Test
void testDataProviderThreadCount() {
var op = new TestNgOperation().dataProviderThreadCount(1);
- assertThat(op.options.get("-dataproviderthreadcount")).isEqualTo("1");
+ assertThat(op.options().get("-dataproviderthreadcount")).isEqualTo("1");
}
@Test
void testDependencyInjectorFactory() {
var op = new TestNgOperation().dependencyInjectorFactory(FOO);
- assertThat(op.options.get("-dependencyinjectorfactory")).isEqualTo(FOO);
+ assertThat(op.options().get("-dependencyinjectorfactory")).isEqualTo(FOO);
}
@Test
void testDirectory() {
+ var foo = new File("FOO");
+
var op = new TestNgOperation().directory(FOO);
- assertThat(op.options.get("-d")).isEqualTo(FOO);
+ assertThat(op.options().get("-d")).as("as string").isEqualTo(FOO);
+
+ op = new TestNgOperation().directory(foo);
+ assertThat(op.options().get("-d")).as("as file").isEqualTo(foo.getAbsolutePath());
+
+ op = new TestNgOperation().directory(foo.toPath());
+ assertThat(op.options().get("-d")).as("as path").isEqualTo(foo.getAbsolutePath());
}
@Test
void testExcludeGroups() {
var op = new TestNgOperation().excludeGroups(FOO, BAR);
- assertThat(op.options.get("-excludegroups")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(op.options().get("-excludegroups")).isEqualTo(String.format("%s,%s", FOO, BAR));
op = new TestNgOperation().excludeGroups(List.of(FOO, BAR));
- assertThat(op.options.get("-excludegroups")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(op.options().get("-excludegroups")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
}
@Test
@@ -97,10 +183,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())
@@ -135,276 +220,304 @@ class TestNgOperationTest {
@Test
void testFailWheneverEverythingSkipped() {
var op = new TestNgOperation().failWhenEverythingSkipped(false);
- assertThat(op.options.get("-failwheneverythingskipped")).isEqualTo("false");
+ assertThat(op.options().get("-failwheneverythingskipped")).isEqualTo("false");
op = new TestNgOperation().failWhenEverythingSkipped(true);
- assertThat(op.options.get("-failwheneverythingskipped")).isEqualTo("true");
+ assertThat(op.options().get("-failwheneverythingskipped")).isEqualTo("true");
}
@Test
void testFailurePolicy() {
var op = new TestNgOperation().failurePolicy(TestNgOperation.FailurePolicy.CONTINUE);
- assertThat(op.options.get("-configfailurepolicy")).isEqualTo("continue");
+ assertThat(op.options().get("-configfailurepolicy")).isEqualTo("continue");
op = new TestNgOperation().failurePolicy(TestNgOperation.FailurePolicy.SKIP);
- assertThat(op.options.get("-configfailurepolicy")).isEqualTo("skip");
+ assertThat(op.options().get("-configfailurepolicy")).isEqualTo("skip");
}
@Test
void testGenerateResultsPerSuite() {
var op = new TestNgOperation().generateResultsPerSuite(false);
- assertThat(op.options.get("-generateResultsPerSuite")).isEqualTo("false");
+ assertThat(op.options().get("-generateResultsPerSuite")).isEqualTo("false");
op = new TestNgOperation().generateResultsPerSuite(true);
- assertThat(op.options.get("-generateResultsPerSuite")).isEqualTo("true");
+ assertThat(op.options().get("-generateResultsPerSuite")).isEqualTo("true");
}
@Test
void testGroups() {
var op = new TestNgOperation().groups(FOO, BAR);
- assertThat(op.options.get("-groups")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(op.options().get("-groups")).isEqualTo(String.format("%s,%s", FOO, BAR));
+
+ op.groups(List.of("group3", "group4"));
+ assertThat(op.options().get("-groups")).isEqualTo("group3,group4");
+
}
@Test
void testIgnoreMissedTestName() {
var op = new TestNgOperation().ignoreMissedTestName(false);
- assertThat(op.options.get("-ignoreMissedTestNames")).isEqualTo("false");
+ assertThat(op.options().get("-ignoreMissedTestNames")).isEqualTo("false");
op = new TestNgOperation().ignoreMissedTestName(true);
- assertThat(op.options.get("-ignoreMissedTestNames")).isEqualTo("true");
+ assertThat(op.options().get("-ignoreMissedTestNames")).isEqualTo("true");
}
@Test
void testIncludeAllDataDrivenTestsWhenSkipping() {
var op = new TestNgOperation().includeAllDataDrivenTestsWhenSkipping(false);
- assertThat(op.options.get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("false");
+ assertThat(op.options().get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("false");
op = new TestNgOperation().includeAllDataDrivenTestsWhenSkipping(true);
- assertThat(op.options.get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("true");
+ assertThat(op.options().get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("true");
}
@Test
void testJar() {
var op = new TestNgOperation().testJar(FOO);
- assertThat(op.options.get("-testjar")).isEqualTo(FOO);
+ assertThat(op.options().get("-testjar")).isEqualTo(FOO);
}
@Test
void testJunit() {
var op = new TestNgOperation().jUnit(false);
- assertThat(op.options.get("-junit")).isEqualTo("false");
+ assertThat(op.options().get("-junit")).isEqualTo("false");
op = new TestNgOperation().jUnit(true);
- assertThat(op.options.get("-junit")).isEqualTo("true");
+ assertThat(op.options().get("-junit")).isEqualTo("true");
}
@Test
void testListener() {
var ops = new TestNgOperation().listener(FOO, BAR);
- assertThat(ops.options.get("-listener")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-listener")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().listener(List.of(FOO, BAR));
- assertThat(ops.options.get("-listener")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-listener")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
}
@Test
void testMethodDetectors() {
var op = new TestNgOperation().methodSelectors(FOO, BAR);
- assertThat(op.options.get("-methodselectors")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(op.options().get("-methodselectors")).isEqualTo(String.format("%s,%s", FOO, BAR));
op = new TestNgOperation().methodSelectors(List.of(FOO, BAR));
- assertThat(op.options.get("-methodselectors")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(op.options().get("-methodselectors")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
}
@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
void testMixed() {
var op = new TestNgOperation().mixed(false);
- assertThat(op.options.get("-mixed")).isEqualTo("false");
+ assertThat(op.options().get("-mixed")).isEqualTo("false");
op = new TestNgOperation().mixed(true);
- assertThat(op.options.get("-mixed")).isEqualTo("true");
+ assertThat(op.options().get("-mixed")).isEqualTo("true");
}
@Test
void testName() {
var op = new TestNgOperation().testName(FOO);
- assertThat(op.options.get("-testname")).isEqualTo("\"" + FOO + '\"');
+ assertThat(op.options().get("-testname")).isEqualTo("\"" + FOO + '\"');
}
@Test
void testNames() {
var ops = new TestNgOperation().testNames(FOO, BAR);
- assertThat(ops.options.get("-testnames")).isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR));
+ assertThat(ops.options().get("-testnames")).isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR));
new TestNgOperation().testNames(List.of(FOO, BAR));
- assertThat(ops.options.get("-testnames")).as("as list").isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR));
+ assertThat(ops.options().get("-testnames")).as("as list").isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR));
}
@Test
void testObjectFactory() {
var ops = new TestNgOperation().objectFactory(FOO, BAR);
- assertThat(ops.options.get("-objectfactory")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-objectfactory")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().objectFactory(List.of(FOO, BAR));
- assertThat(ops.options.get("-objectfactory")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-objectfactory")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
}
@Test
void testOverrideIncludedMethods() {
var ops = new TestNgOperation().overrideIncludedMethods(FOO, BAR);
- assertThat(ops.options.get("-overrideincludedmethods")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-overrideincludedmethods")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().overrideIncludedMethods(List.of(FOO, BAR));
- assertThat(ops.options.get("-overrideincludedmethods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-overrideincludedmethods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
}
@Test
void testPackages() {
var op = new TestNgOperation().packages(FOO, BAR);
- assertThat(op.packages).contains(FOO).contains(BAR);
+ assertThat(op.packages()).contains(FOO).contains(BAR);
op = new TestNgOperation().packages(List.of(FOO, BAR));
- assertThat(op.packages).as("as list").contains(FOO).contains(BAR);
+ assertThat(op.packages()).as("as list").contains(FOO).contains(BAR);
}
@Test
void testParallel() {
var op = new TestNgOperation().parallel(TestNgOperation.Parallel.TESTS);
- assertThat(op.options.get("-parallel")).isEqualTo("tests");
+ assertThat(op.options().get("-parallel")).isEqualTo("tests");
op = new TestNgOperation().parallel(TestNgOperation.Parallel.METHODS);
- assertThat(op.options.get("-parallel")).isEqualTo("methods");
+ assertThat(op.options().get("-parallel")).isEqualTo("methods");
op = new TestNgOperation().parallel(TestNgOperation.Parallel.CLASSES);
- assertThat(op.options.get("-parallel")).isEqualTo("classes");
+ assertThat(op.options().get("-parallel")).isEqualTo("classes");
}
@Test
void testPort() {
var op = new TestNgOperation().port(1);
- assertThat(op.options.get("-port")).isEqualTo("1");
+ assertThat(op.options().get("-port")).isEqualTo("1");
}
@Test
void testPropagateDataProviderFailureAsTestFailure() {
var op = new TestNgOperation().propagateDataProviderFailureAsTestFailure(false);
- assertThat(op.options.get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("false");
+ assertThat(op.options().get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("false");
op = new TestNgOperation().propagateDataProviderFailureAsTestFailure(true);
- assertThat(op.options.get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("true");
+ assertThat(op.options().get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("true");
}
@Test
void testReported() {
var op = new TestNgOperation().reporter(FOO);
- assertThat(op.options.get("-reporter")).isEqualTo(FOO);
+ assertThat(op.options().get("-reporter")).isEqualTo(FOO);
}
@Test
void testRunFactory() {
var op = new TestNgOperation().testRunFactory(FOO);
- assertThat(op.options.get("-testrunfactory")).isEqualTo(FOO);
+ assertThat(op.options().get("-testrunfactory")).isEqualTo(FOO);
}
@Test
void testShareThreadPoolForDataProviders() {
var op = new TestNgOperation().shareThreadPoolForDataProviders(true);
- assertThat(op.options.get("-shareThreadPoolForDataProviders")).isEqualTo("true");
+ assertThat(op.options().get("-shareThreadPoolForDataProviders")).isEqualTo("true");
op = new TestNgOperation().shareThreadPoolForDataProviders(false);
- assertThat(op.options.get("-shareThreadPoolForDataProviders")).isNull();
+ assertThat(op.options().get("-shareThreadPoolForDataProviders")).isNull();
}
@Test
void testSourceDir() {
+ var foo = new File(FOO);
+ var bar = new File(BAR);
+
+ var foobar = String.format("%s;%s", FOO, BAR);
var op = new TestNgOperation().sourceDir(FOO, BAR);
- assertThat(op.options.get("-sourcedir")).isEqualTo(String.format("%s;%s", FOO, BAR));
+ assertThat(op.options().get("-sourcedir")).as("String...").isEqualTo(foobar);
op = new TestNgOperation().sourceDir(List.of(FOO, BAR));
- assertThat(op.options.get("-sourcedir")).as("as list").isEqualTo(String.format("%s;%s", FOO, BAR));
+ assertThat(op.options().get("-sourcedir")).as("List(String...)").isEqualTo(foobar);
+
+ foobar = String.format("%s;%s", foo.getAbsolutePath(), bar.getAbsolutePath());
+ op = new TestNgOperation().sourceDir(foo, bar);
+ assertThat(op.options().get("-sourcedir")).as("File...").isEqualTo(foobar);
+
+ op = new TestNgOperation().sourceDirFiles(List.of(foo, bar));
+ assertThat(op.options().get("-sourcedir")).as("List(String...)").isEqualTo(foobar);
+
+ op = new TestNgOperation().sourceDir(foo.toPath(), bar.toPath());
+ assertThat(op.options().get("-sourcedir")).as("Path...").isEqualTo(foobar);
+
+ op = new TestNgOperation().sourceDirPaths(List.of(foo.toPath(), bar.toPath()));
+ assertThat(op.options().get("-sourcedir")).as("List(Path...)").isEqualTo(foobar);
}
@Test
void testSpiListenersToSkip() {
var ops = new TestNgOperation().spiListenersToSkip(FOO, BAR);
- assertThat(ops.options.get("-spilistenerstoskip")).isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-spilistenerstoskip")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().spiListenersToSkip(List.of(FOO, BAR));
- assertThat(ops.options.get("-spilistenerstoskip")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
+ assertThat(ops.options().get("-spilistenerstoskip")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
}
@Test
void testSuiteName() {
var op = new TestNgOperation().suiteName(FOO);
- assertThat(op.options.get("-suitename")).isEqualTo("\"" + FOO + '\"');
+ assertThat(op.options().get("-suitename")).isEqualTo("\"" + FOO + '\"');
}
@Test
void testSuiteThreadPoolSize() {
var op = new TestNgOperation().suiteThreadPoolSize(1);
- assertThat(op.options.get("-suitethreadpoolsize")).isEqualTo("1");
+ assertThat(op.options().get("-suitethreadpoolsize")).isEqualTo("1");
}
@Test
void testSuites() {
var op = new TestNgOperation().suites(FOO, BAR);
- assertThat(op.suites).contains(FOO).contains(BAR);
+ assertThat(op.suites()).contains(FOO).contains(BAR);
op = new TestNgOperation().suites(List.of(FOO, BAR));
- assertThat(op.suites).as("as list").contains(FOO).contains(BAR);
+ assertThat(op.suites()).as("as list").contains(FOO).contains(BAR);
}
@Test
void testThreadCount() {
var op = new TestNgOperation().threadCount(1);
- assertThat(op.options.get("-threadcount")).isEqualTo("1");
+ assertThat(op.options().get("-threadcount")).isEqualTo("1");
}
@Test
void testThreadPoolFactoryClass() {
var op = new TestNgOperation().threadPoolFactoryClass(FOO);
- assertThat(op.options.get("-threadpoolfactoryclass")).isEqualTo(FOO);
+ assertThat(op.options().get("-threadpoolfactoryclass")).isEqualTo(FOO);
}
@Test
void testUseDefaultListeners() {
var op = new TestNgOperation().useDefaultListeners(false);
- assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("false");
+ assertThat(op.options().get("-usedefaultlisteners")).isEqualTo("false");
op = new TestNgOperation().useDefaultListeners(true);
- assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("true");
+ assertThat(op.options().get("-usedefaultlisteners")).isEqualTo("true");
}
@Test
void testUseGlobalThreadPool() {
var op = new TestNgOperation().useGlobalThreadPool(true);
- assertThat(op.options.get("-useGlobalThreadPool")).isEqualTo("true");
+ assertThat(op.options().get("-useGlobalThreadPool")).isEqualTo("true");
op = new TestNgOperation().useGlobalThreadPool(false);
- assertThat(op.options.get("-useGlobalThreadPool")).isNull();
+ assertThat(op.options().get("-useGlobalThreadPool")).isNull();
}
@Test
void testVerbose() {
var op = new TestNgOperation().log(1);
- assertThat(op.options.get("-log")).isEqualTo("1");
+ assertThat(op.options().get("-log")).isEqualTo("1");
op = new TestNgOperation().verbose(1);
- assertThat(op.options.get("-verbose")).isEqualTo("1");
+ assertThat(op.options().get("-verbose")).isEqualTo("1");
}
@Test
void testXmlPathInJar() {
+ var foo = new File(FOO);
var op = new TestNgOperation().xmlPathInJar(FOO);
- assertThat(op.options.get("-xmlpathinjar")).isEqualTo(FOO);
+ assertThat(op.options().get("-xmlpathinjar")).as("as string").isEqualTo(FOO);
+
+ op = new TestNgOperation().xmlPathInJar(foo);
+ assertThat(op.options().get("-xmlpathinjar")).as("as file").isEqualTo(foo.getAbsolutePath());
+
+ op = new TestNgOperation().xmlPathInJar(foo.toPath());
+ assertThat(op.options().get("-xmlpathinjar")).as("as path").isEqualTo(foo.getAbsolutePath());
}
}
diff --git a/src/test/resources/testng-args.txt b/src/test/resources/testng-args.txt
new file mode 100644
index 0000000..8eec8d5
--- /dev/null
+++ b/src/test/resources/testng-args.txt
@@ -0,0 +1,38 @@
+-alwaysrunlisteners
+-configfailurepolicy
+-d
+-dataproviderthreadcount
+-dependencyinjectorfactory
+-excludegroups
+-failwheneverythingskipped
+-generateResultsPerSuite
+-groups
+-ignoreMissedTestNames
+-includeAllDataDrivenTestsWhenSkipping
+-listener
+-listenercomparator
+-listenerfactory
+-log
+-methods
+-methodselectors
+-mixed
+-objectfactory
+-overrideincludedmethods
+-parallel
+-propagateDataProviderFailureAsTestFailure
+-reporter
+-shareThreadPoolForDataProviders
+-spilistenerstoskip
+-suitename
+-suitethreadpoolsize
+-testclass
+-testjar
+-testname
+-testnames
+-testrunfactory
+-threadcount
+-threadpoolfactoryclass
+-usedefaultlisteners
+-useGlobalThreadPool
+-verbose
+-xmlpathinjar
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