diff --git a/.idea/copyright/Apache_License.xml b/.idea/copyright/Apache_License.xml index 15687f4..ade80da 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/checkcliargs.sh b/checkcliargs.sh new file mode 100755 index 0000000..0bad85a --- /dev/null +++ b/checkcliargs.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +MAIN="org.testng.TestNG" +TMPNEW=/tmp/checkcliargs-new +TMPOLD=/tmp/checkcliargs-old + +java -cp "lib/test/*" $MAIN >$TMPNEW +java -cp "examples/lib/test/*" $MAIN >$TMPOLD + +diff $TMPOLD $TMPNEW + +rm -rf $TMPNEW $TMPOLD diff --git a/examples/src/test/java/com/example/ExamplesTest.java b/examples/src/test/java/com/example/ExamplesTest.java index 8d93e01..620f3ae 100644 --- a/examples/src/test/java/com/example/ExamplesTest.java +++ b/examples/src/test/java/com/example/ExamplesTest.java @@ -3,18 +3,16 @@ package com.example; import org.testng.Assert; import org.testng.annotations.Test; -class ExampleTest { - public static void main(String[] args) { - new ExampleTest().verifyHello(); - } +class ExamplesTest { + private final ExamplesLib example = new ExamplesLib(); @Test - void testFail() { - Assert.fail("failed"); + void foo() { + Assert.assertNotEquals(example.getMessage(), "foo"); } @Test void verifyHello() { - Assert.assertTrue(true); + Assert.assertEquals(example.getMessage(), "Hello World!"); } } \ 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 d88d787..ce1ebd9 100644 --- a/src/bld/java/rife/bld/extension/TestNgOperationBuild.java +++ b/src/bld/java/rife/bld/extension/TestNgOperationBuild.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 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. @@ -50,7 +50,7 @@ public class TestNgOperationBuild extends Project { .include(dependency("org.testng", "testng", version(7, 9, 0))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1))) - .include(dependency("org.assertj", "assertj-core", version(3, 24, 2))); + .include(dependency("org.assertj", "assertj-core", version(3, 25, 2))); javadocOperation() .javadocOptions() diff --git a/src/main/java/rife/bld/extension/TestNgOperation.java b/src/main/java/rife/bld/extension/TestNgOperation.java index b95445b..33c15d5 100644 --- a/src/main/java/rife/bld/extension/TestNgOperation.java +++ b/src/main/java/rife/bld/extension/TestNgOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 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. @@ -561,6 +561,19 @@ public class TestNgOperation extends AbstractProcessOperation { return this; } + /** + * Should TestNG use a global Shared ThreadPool (At suite level) for running data providers. + * + * @param shareThreadPoolForDataProviders {@code true} or {@code false} + * @return this operation instance + */ + public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolForDataProviders) { + if (shareThreadPoolForDataProviders) { + options.put("-shareThreadPoolForDataProviders", String.valueOf(shareThreadPoolForDataProviders)); + } + 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 @@ -845,6 +858,19 @@ public class TestNgOperation extends AbstractProcessOperation { return this; } + /** + * Should TestNG use a global Shared ThreadPool (At suite level) for running regular and data driven tests. + * + * @param useGlobalThreadPool {@code true} or {@code false} + * @return this operation instance + */ + public TestNgOperation useGlobalThreadPool(boolean useGlobalThreadPool) { + if (useGlobalThreadPool) { + options.put("-useGlobalThreadPool", String.valueOf(useGlobalThreadPool)); + } + return this; + } + /** * Set the Level of verbosity. * @@ -921,4 +947,4 @@ public class TestNgOperation extends AbstractProcessOperation { */ CONTINUE } -} \ No newline at end of file +} diff --git a/src/test/java/rife/bld/extension/TestNgSimple2Test.java b/src/test/java/rife/bld/extension/TestNgExample.java similarity index 66% rename from src/test/java/rife/bld/extension/TestNgSimple2Test.java rename to src/test/java/rife/bld/extension/TestNgExample.java index d09159d..c2dc3e0 100644 --- a/src/test/java/rife/bld/extension/TestNgSimple2Test.java +++ b/src/test/java/rife/bld/extension/TestNgExample.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 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,22 +16,15 @@ package rife.bld.extension; -import org.testng.Assert; -import org.testng.annotations.Test; - /** - * Implements the TestNgSimpleTest class. + * Implements the TestNgExample class. * * @author Erik C. Thauvin * @since 1.0 */ -class TestNgSimple2Test { - public static void main(String[] args) { - new TestNgSimple2Test().verifyHello(); - } - - @Test - void verifyHello() { - Assert.assertTrue(true); +@SuppressWarnings("PMD.TestClassWithoutTestCases") +class TestNgExample { + public String getMessage() { + return "Hello World!"; } } diff --git a/src/test/java/rife/bld/extension/TestNgSimpleTest.java b/src/test/java/rife/bld/extension/TestNgExampleTest.java similarity index 71% rename from src/test/java/rife/bld/extension/TestNgSimpleTest.java rename to src/test/java/rife/bld/extension/TestNgExampleTest.java index 8007a15..a2c35b9 100644 --- a/src/test/java/rife/bld/extension/TestNgSimpleTest.java +++ b/src/test/java/rife/bld/extension/TestNgExampleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 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. @@ -20,23 +20,21 @@ import org.testng.Assert; import org.testng.annotations.Test; /** - * Implements the TestNgSimpleTest class. + * Implements the TestNgExampleTest class. * * @author Erik C. Thauvin * @since 1.0 */ -class TestNgSimpleTest { - public static void main(String[] args) { - new TestNgSimpleTest().verifyHello(); - } +class TestNgExampleTest { + private final TestNgExample example = new TestNgExample(); @Test - void testFail() { - Assert.fail("failed"); + void foo() { + Assert.assertEquals(example.getMessage(), "foo"); } @Test void verifyHello() { - Assert.assertTrue(true); + Assert.assertEquals(example.getMessage(), "Hello World!"); } } diff --git a/src/test/java/rife/bld/extension/TestNgOperationTest.java b/src/test/java/rife/bld/extension/TestNgOperationTest.java index 88a7fa3..3bdc424 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 the original author or authors. + * Copyright 2023-2024 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. @@ -85,7 +85,7 @@ class TestNgOperationTest { void testExecute() { assertThatThrownBy(() -> new TestNgOperation().fromProject(new Project()) - .testClass("rife.bld.extension.TestNgSimpleTest") + .testClass("rife.bld.extension.TestNgExampleTest") .execute()) .as("with testClass").isInstanceOf(ExitStatusException.class); @@ -97,8 +97,8 @@ class TestNgOperationTest { assertThatCode(() -> new TestNgOperation().fromProject(new Project()) - .testClass("rife.bld.extension.TestNgSimpleTest") - .methods("rife.bld.extension.TestNgSimpleTest.verifyHello") + .testClass("rife.bld.extension.TestNgExampleTest") + .methods("rife.bld.extension.TestNgExampleTest.verifyHello") .execute()) .as("with methods").doesNotThrowAnyException(); @@ -110,14 +110,14 @@ class TestNgOperationTest { assertThatCode(() -> new TestNgOperation().fromProject(new Project()) - .suites("src/test/resources/testng3.xml") + .suites("src/test/resources/testng2.xml") .log(2) .execute()) - .as("suite 3").doesNotThrowAnyException(); + .as("suite 2 - log ").doesNotThrowAnyException(); assertThatCode(() -> new TestNgOperation().fromProject(new Project()) - .suites("src/test/resources/testng3.xml") + .suites("src/test/resources/testng2.xml") .testClasspath("lib/test/*", "build/main", "build/test") .log(2) .execute()) @@ -125,7 +125,7 @@ class TestNgOperationTest { assertThatCode(() -> new TestNgOperation().fromProject(new Project()) - .suites("src/test/resources/testng3.xml") + .suites("src/test/resources/testng2.xml") .testClasspath(List.of("lib/test/*", "build/main", "build/test")) .log(2) .execute()) @@ -315,6 +315,15 @@ class TestNgOperationTest { assertThat(op.options.get("-testrunfactory")).isEqualTo(FOO); } + @Test + void testShareThreadPoolForDataProviders() { + var op = new TestNgOperation().shareThreadPoolForDataProviders(true); + assertThat(op.options.get("-shareThreadPoolForDataProviders")).isEqualTo("true"); + + op = new TestNgOperation().shareThreadPoolForDataProviders(false); + assertThat(op.options.get("-shareThreadPoolForDataProviders")).isNull(); + } + @Test void testSourceDir() { var op = new TestNgOperation().sourceDir(FOO, BAR); @@ -375,6 +384,15 @@ class TestNgOperationTest { assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("true"); } + @Test + void testUseGlobalThreadPool() { + var op = new TestNgOperation().useGlobalThreadPool(true); + assertThat(op.options.get("-useGlobalThreadPool")).isEqualTo("true"); + + op = new TestNgOperation().useGlobalThreadPool(false); + assertThat(op.options.get("-useGlobalThreadPool")).isNull(); + } + @Test void testVerbose() { var op = new TestNgOperation().log(1); diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml index 41fd8ae..8ad378e 100644 --- a/src/test/resources/testng.xml +++ b/src/test/resources/testng.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/src/test/resources/testng2.xml b/src/test/resources/testng2.xml index 01168b7..44ddf38 100644 --- a/src/test/resources/testng2.xml +++ b/src/test/resources/testng2.xml @@ -2,9 +2,9 @@ - + - + diff --git a/src/test/resources/testng3.xml b/src/test/resources/testng3.xml deleted file mode 100644 index baa78e5..0000000 --- a/src/test/resources/testng3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - -