From b69faf34d6da0a8e4ce1601e306531b5932ad782 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 21 Aug 2023 07:43:18 -0700 Subject: [PATCH 01/78] Updated bld badge --- README.md | 4 ++-- src/bld/java/rife/bld/extension/TestNgOperationBuild.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ea15b98..a7e6693 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) -[![bld](https://img.shields.io/badge/1.7.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) +[![bld](https://img.shields.io/badge/1.7.2-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) [![Release](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/releases/com/uwyn/rife2/bld-testng/maven-metadata.xml?color=blue)](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-testng) [![Snapshot](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/snapshots/com/uwyn/rife2/bld-testng/maven-metadata.xml?label=snapshot)](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-testng) [![GitHub CI](https://github.com/rife2/bld-testng/actions/workflows/bld.yml/badge.svg)](https://github.com/rife2/bld-testng/actions/workflows/bld.yml) @@ -52,4 +52,4 @@ Don't forget to add a TestNG test dependency to your build file, as it is not pr repositories = List.of(MAVEN_CENTRAL); scope(test).include(dependency("org.testng", "testng", version(7, 8, 0))); -``` \ No newline at end of file +``` diff --git a/src/bld/java/rife/bld/extension/TestNgOperationBuild.java b/src/bld/java/rife/bld/extension/TestNgOperationBuild.java index bcebfbe..30112a2 100644 --- a/src/bld/java/rife/bld/extension/TestNgOperationBuild.java +++ b/src/bld/java/rife/bld/extension/TestNgOperationBuild.java @@ -34,7 +34,7 @@ public class TestNgOperationBuild extends Project { public TestNgOperationBuild() { pkg = "rife.bld.extension"; name = "bld-testng"; - version = version(0, 9, 1); + version = version(0, 9, 2, "SNAPSHOT"); javaRelease = 17; downloadSources = true; From f92ab27463ed600ed79483c16a7dba67c22cda66 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 28 Aug 2023 14:21:08 -0700 Subject: [PATCH 02/78] Added support for collection arguments --- .../rife/bld/extension/TestNgOperation.java | 189 +++++++++++++++++- .../bld/extension/TestNgOperationTest.java | 47 +++++ 2 files changed, 235 insertions(+), 1 deletion(-) diff --git a/src/main/java/rife/bld/extension/TestNgOperation.java b/src/main/java/rife/bld/extension/TestNgOperation.java index ec567c9..49c9b5b 100644 --- a/src/main/java/rife/bld/extension/TestNgOperation.java +++ b/src/main/java/rife/bld/extension/TestNgOperation.java @@ -98,12 +98,24 @@ public class TestNgOperation extends AbstractProcessOperation { /** * The list of groups you want to be excluded from this run. + * + * @see #excludeGroups(Collection) */ public TestNgOperation excludeGroups(String... group) { options.put("-excludegroups", String.join(",", group)); return this; } + /** + * The list of groups you want to be excluded from this run. + * + * @see #excludeGroups(String...) + */ + public TestNgOperation excludeGroups(Collection group) { + options.put("-excludegroups", String.join(",", group)); + return this; + } + /** * Part of the {@link #execute execute} operation, constructs the command list to use for building the process. */ @@ -119,7 +131,7 @@ public class TestNgOperation extends AbstractProcessOperation { options.put("d", Path.of(project.buildDirectory().getPath(), "test-output").toString()); } - List args = new ArrayList<>(); + final List args = new ArrayList<>(); args.add(javaTool()); args.add("-cp"); @@ -197,12 +209,26 @@ public class TestNgOperation extends AbstractProcessOperation { * The list of groups you want to run. * *

For example: {@code "windows", "linux", "regression}

+ * + * @see #groups(Collection) */ public TestNgOperation groups(String... group) { options.put("-groups", String.join(",", group)); return this; } + /** + * The list of groups you want to run. + * + *

For example: {@code "windows", "linux", "regression}

+ * + * @see #groups(String...) + */ + public TestNgOperation groups(Collection group) { + options.put("-groups", String.join(",", group)); + return this; + } + /** * Ignore missed test names given by {@link #testNames(String...) testNames} and continue to run existing tests, * if any. @@ -237,12 +263,25 @@ public class TestNgOperation extends AbstractProcessOperation { /** * The list of {@code .class} files or list of class names implementing {@code ITestListener} or * {@code ISuiteListener} + * + * @see #listener(Collection) */ public TestNgOperation listener(String... listener) { options.put("-listener", String.join(",", listener)); return this; } + /** + * The list of {@code .class} files or list of class names implementing {@code ITestListener} or + * {@code ISuiteListener} + * + * @see #listener(String...) + */ + public TestNgOperation listener(Collection listener) { + options.put("-listener", String.join(",", listener)); + return this; + } + /** * Set the Level of verbosity. * @@ -257,22 +296,50 @@ public class TestNgOperation extends AbstractProcessOperation { * Specifies the list of {@code .class} files or class names implementing {@code IMethodSelector}. * *

For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"}

+ * + * @see #methodSelectors(Collection) */ public TestNgOperation methodSelectors(String... selector) { options.put("-methodselectors", String.join(",", selector)); 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"}

+ * + * @see #methodSelectors(String...) + */ + public TestNgOperation methodSelectors(Collection selector) { + options.put("-methodselectors", String.join(",", selector)); + return this; + } + /** * Lets you specify individual methods to run. * *

For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"}

+ * + * @see #methods(Collection) */ public TestNgOperation methods(String... method) { options.put("-methods", String.join(",", method)); return this; } + /** + * Lets you specify individual methods to run. + * + *

For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"}

+ * + * @see #methods(String...) + */ + public TestNgOperation methods(Collection method) { + options.put("-methods", String.join(",", method)); + return this; + } + /** * Mixed mode autodetects the type of current test and run it with appropriate runner. * @@ -285,33 +352,74 @@ public class TestNgOperation extends AbstractProcessOperation { /** * The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}. + * + * @see #objectFactory(Collection) */ public TestNgOperation objectFactory(String... factory) { options.put("-objectfactory", String.join(",", factory)); return this; } + /** + * The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}. + * + * @see #objectFactory(String...) + */ + public TestNgOperation objectFactory(Collection factory) { + options.put("-objectfactory", String.join(",", factory)); + return this; + } + /** * The list of fully qualified class names of listeners that should be skipped from being wired in via * Service Loaders. + * + * @see #overrideIncludedMethods(Collection) */ public TestNgOperation overrideIncludedMethods(String... method) { options.put("-overrideincludedmethods", String.join(",", method)); return this; } + /** + * The list of fully qualified class names of listeners that should be skipped from being wired in via + * Service Loaders. + * + * @see #overrideIncludedMethods(String...) + */ + public TestNgOperation overrideIncludedMethods(Collection method) { + options.put("-overrideincludedmethods", String.join(",", method)); + return this; + } + /** * The list of packages to include in this test. * If the package name ends with .* then subpackages are included too. * Required if no {@link #suites(String... suites)} specified. * *

For example: {@code "com.example", "test.sample.*"}

+ * + * @see #packages(Collection) */ public TestNgOperation packages(String... name) { packages.addAll(Arrays.stream(name).toList()); return this; } + /** + * The list of packages to include in this test. + * If the package name ends with .* then subpackages are included too. + * Required if no {@link #suites(String... suites)} specified. + * + *

For example: {@code "com.example", "test.sample.*"}

+ * + * @see #packages(String...) + */ + public TestNgOperation packages(Collection name) { + packages.addAll(name); + return this; + } + /** * 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. @@ -354,21 +462,48 @@ public class TestNgOperation extends AbstractProcessOperation { * 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"}). + * + * @see #sourceDir(String...) */ public TestNgOperation sourceDir(String... directory) { options.put("-sourcedir", String.join(";", directory)); return this; } + /** + * 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"}). + * + * @see #sourceDir(String...) + */ + public TestNgOperation sourceDir(Collection directory) { + options.put("-sourcedir", String.join(";", directory)); + return this; + } + /** * Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via * Service Loaders. + * + * @see #spiListenersToSkip(Collection) */ public TestNgOperation spiListenersToSkip(String... listenerToSkip) { options.put("-spilistenerstoskip", String.join(",", listenerToSkip)); return this; } + /** + * Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via + * Service Loaders. + * + * @see #spiListenersToSkip(String...) + */ + public TestNgOperation spiListenersToSkip(Collection listenerToSkip) { + options.put("-spilistenerstoskip", String.join(",", listenerToSkip)); + return this; + } + /** * 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. @@ -391,12 +526,26 @@ public class TestNgOperation extends AbstractProcessOperation { * Specifies the suites to run. * *

For example: {@code "testng.xml", "testng2.xml"}

+ * + * @see #suites(Collection) */ public TestNgOperation suites(String... suite) { suites.addAll(Arrays.stream(suite).toList()); return this; } + /** + * Specifies the suites to run. + * + *

For example: {@code "testng.xml", "testng2.xml"}

+ * + * @see #suites(String...) + */ + public TestNgOperation suites(Collection suite) { + suites.addAll(suite); + return this; + } + /** * Create a test file and delete it on exit. */ @@ -410,20 +559,46 @@ public class TestNgOperation extends AbstractProcessOperation { * Specifies the list of class files. * *

For example: {@code "org.foo.Test1","org.foo.test2"}

+ * + * @see #testClass(Collection) */ public TestNgOperation testClass(String... aClass) { options.put("-testclass", String.join(",", aClass)); return this; } + /** + * Specifies the list of class files. + * + *

For example: {@code "org.foo.Test1","org.foo.test2"}

+ * + * @see #testClass(String...) + */ + public TestNgOperation testClass(Collection aClass) { + options.put("-testclass", String.join(",", aClass)); + return this; + } + /** * Specifies the classpath entries used to run tests. + * + * @see #testClasspath(String...) */ public TestNgOperation testClasspath(String... entry) { testClasspath.addAll(Arrays.stream(entry).toList()); return this; } + /** + * Specifies the classpath entries used to run tests. + * + * @see #testClasspath(String...) + */ + public TestNgOperation testClasspath(Collection entry) { + testClasspath.addAll(entry); + return this; + } + /** * 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 @@ -445,12 +620,24 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Only tests defined in a {@code } tag matching one of these names will be run. + * + * @see #testNames(Collection) */ public TestNgOperation testNames(String... name) { options.put("-testnames", Arrays.stream(name).map(s -> '"' + s + '"').collect(Collectors.joining(","))); return this; } + /** + * Only tests defined in a {@code } tag matching one of these names will be run. + * + * @see #testName(String) + */ + public TestNgOperation testNames(Collection name) { + options.put("-testnames", name.stream().map(s -> '"' + s + '"').collect(Collectors.joining(","))); + return this; + } + /** * Specifies the factory used to create tests. */ diff --git a/src/test/java/rife/bld/extension/TestNgOperationTest.java b/src/test/java/rife/bld/extension/TestNgOperationTest.java index bf61aaa..6c56a69 100644 --- a/src/test/java/rife/bld/extension/TestNgOperationTest.java +++ b/src/test/java/rife/bld/extension/TestNgOperationTest.java @@ -20,6 +20,8 @@ import org.junit.jupiter.api.Test; import rife.bld.Project; // NOPMD import rife.bld.operations.exceptions.ExitStatusException; +import java.util.List; + import static org.assertj.core.api.Assertions.*; /** @@ -46,6 +48,10 @@ class TestNgOperationTest { void testClass() { var op = new TestNgOperation().testClass(FOO, BAR); assertThat(op.options.get(TestNgOperation.TEST_CLASS_ARG)).isEqualTo(String.format("%s,%s", FOO, BAR)); + + new TestNgOperation().testClass(List.of(FOO, BAR)); + assertThat(op.options.get(TestNgOperation.TEST_CLASS_ARG)).as("as list") + .isEqualTo(String.format("%s,%s", FOO, BAR)); } @Test @@ -70,6 +76,9 @@ class TestNgOperationTest { void testExcludeGroups() { var op = new TestNgOperation().excludeGroups(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)); } @Test @@ -113,6 +122,14 @@ class TestNgOperationTest { .log(2) .execute()) .as("with run classpath").doesNotThrowAnyException(); + + assertThatCode(() -> + new TestNgOperation().fromProject(new Project()) + .suites("src/test/resources/testng3.xml") + .testClasspath(List.of("lib/test/*", "build/main", "build/test")) + .log(2) + .execute()) + .as("with run classpath as list").doesNotThrowAnyException(); } @Test @@ -185,18 +202,27 @@ class TestNgOperationTest { void testListener() { var ops = new TestNgOperation().listener(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)); } @Test void testMethodDetectors() { var op = new TestNgOperation().methodSelectors(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)); } @Test void testMethods() { var op = new TestNgOperation().methods(FOO, BAR); assertThat(op.options.get("-methods")).isEqualTo(String.format("%s,%s", FOO, BAR)); + + new TestNgOperation().methods(List.of(FOO, BAR)); + assertThat(op.options.get("-methods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); } @Test @@ -218,24 +244,36 @@ class TestNgOperationTest { void testNames() { var ops = new TestNgOperation().testNames(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)); } @Test void testObjectFactory() { var ops = new TestNgOperation().objectFactory(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)); } @Test void testOverrideIncludedMethods() { var ops = new TestNgOperation().overrideIncludedMethods(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)); } @Test void testPackages() { var op = new TestNgOperation().packages(FOO, 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); } @Test @@ -281,12 +319,18 @@ class TestNgOperationTest { void testSourceDir() { var op = new TestNgOperation().sourceDir(FOO, BAR); assertThat(op.options.get("-sourcedir")).isEqualTo(String.format("%s;%s", FOO, BAR)); + + op = new TestNgOperation().sourceDir(List.of(FOO, BAR)); + assertThat(op.options.get("-sourcedir")).as("as list").isEqualTo(String.format("%s;%s", FOO, BAR)); } @Test void testSpiListenersToSkip() { var ops = new TestNgOperation().spiListenersToSkip(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)); } @Test @@ -305,6 +349,9 @@ class TestNgOperationTest { void testSuites() { var op = new TestNgOperation().suites(FOO, 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); } @Test From 100ce6dc0d5a80f89929be426b3134b397a52efb Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 28 Aug 2023 14:21:58 -0700 Subject: [PATCH 03/78] Added examples link --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a7e6693..5b2a3b5 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,18 @@ public void test throws Exception { .execute(); } ``` + ``` ./bld compile test ``` +- [View Examples](https://github.com/rife2/bld-tetng/tree/master/examples] + Please check the [TestNgOperation documentation](https://rife2.github.io/bld-testng/rife/bld/extension/TestNgOperation.html#method-summary) for all available configuration options. ### TestNG Dependency -Don't forget to add a TestNG test dependency to your build file, as it is not provided by the extension. For example: +Don't forget to add a TestNG `test` dependency to your build file, as it is not provided by the extension. For example: ```java repositories = List.of(MAVEN_CENTRAL); From dd196cd761c7f61cf513e99d494ec0850da8e448 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 28 Aug 2023 14:23:12 -0700 Subject: [PATCH 04/78] Updated copyright --- .idea/copyright/Apache_License.xml | 2 +- .idea/misc.xml | 2 ++ .../bld/extension/TestNgOperationBuild.java | 20 +++++++++---------- .../rife/bld/extension/TestNgOperation.java | 20 +++++++++---------- .../bld/extension/TestNgOperationTest.java | 20 +++++++++---------- .../rife/bld/extension/TestNgSimple2Test.java | 20 +++++++++---------- .../rife/bld/extension/TestNgSimpleTest.java | 20 +++++++++---------- 7 files changed, 53 insertions(+), 51 deletions(-) diff --git a/.idea/copyright/Apache_License.xml b/.idea/copyright/Apache_License.xml index 206aa7d..15687f4 100644 --- a/.idea/copyright/Apache_License.xml +++ b/.idea/copyright/Apache_License.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 52cb5be..b3a2303 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + @@ -9,6 +10,7 @@