From b2ac4ec79258fa0ac953a713819e73dd91085313 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Fri, 16 Jul 2021 09:48:01 +0200 Subject: [PATCH 01/12] Add testng.allowReturnValues configuration parameter --- README.adoc | 13 +++++--- .../testng/engine/ConfiguringListener.java | 31 +++++++++++++++++++ .../testng/engine/DefaultListener.java | 10 +++++- .../testng/engine/LoggingListener.java | 7 +++++ .../testng/engine/TestNGTestEngine.java | 11 ++++--- .../engine/ReportingIntegrationTests.java | 22 +++++++++++-- .../example/basics/ReturnValuesTestCase.java | 21 +++++++++++++ 7 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/junit/support/testng/engine/ConfiguringListener.java create mode 100644 src/testFixtures/java/example/basics/ReturnValuesTestCase.java diff --git a/README.adoc b/README.adoc index 73c6060..adeb51d 100644 --- a/README.adoc +++ b/README.adoc @@ -127,17 +127,20 @@ The engine requires at least JUnit Platform 1.5.x. The following JUnit Platform https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params[configuration parameters] are supported: +`testng.allowReturnValues` (boolean):: +whether methods with return values should be considered test methods (default: `false`) ++ +`testng.listeners` (comma-separated list of fully-qualified class names):: +custom listeners that should be registered when executing tests (default: `""`) ++ `testng.outputDirectory` (file path):: -the output directory for reports (default: "test-output") +the output directory for reports (default: `"test-output"`) + `testng.useDefaultListeners` (boolean):: whether TestNG's default report generating listeners should be used (default: `false`) + -`testng.listeners` (comma-separated list of fully-qualified class names):: -custom listeners that should be registered when executing tests (default: none) -+ `testng.verbose` (integer):: -TestNG's level of verbosity (default: 0) +TestNG's level of verbosity (default: `0`) === Generating TestNG reports diff --git a/src/main/java/org/junit/support/testng/engine/ConfiguringListener.java b/src/main/java/org/junit/support/testng/engine/ConfiguringListener.java new file mode 100644 index 0000000..6c638f0 --- /dev/null +++ b/src/main/java/org/junit/support/testng/engine/ConfiguringListener.java @@ -0,0 +1,31 @@ +/* + * Copyright 2021 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package org.junit.support.testng.engine; + +import java.util.List; + +import org.junit.platform.engine.ConfigurationParameters; +import org.testng.xml.XmlSuite; + +class ConfiguringListener extends DefaultListener { + + private final ConfigurationParameters configurationParameters; + + ConfiguringListener(ConfigurationParameters configurationParameters) { + this.configurationParameters = configurationParameters; + } + + @Override + public void alter(List suites) { + configurationParameters.getBoolean("testng.allowReturnValues") // + .ifPresent(allowReturnValues -> suites.forEach(it -> it.setAllowReturnValues(allowReturnValues))); + } +} diff --git a/src/main/java/org/junit/support/testng/engine/DefaultListener.java b/src/main/java/org/junit/support/testng/engine/DefaultListener.java index d287f22..681f788 100644 --- a/src/main/java/org/junit/support/testng/engine/DefaultListener.java +++ b/src/main/java/org/junit/support/testng/engine/DefaultListener.java @@ -10,6 +10,9 @@ package org.junit.support.testng.engine; +import java.util.List; + +import org.testng.IAlterSuiteListener; import org.testng.IClassListener; import org.testng.IConfigurationListener; import org.testng.ITestClass; @@ -17,8 +20,13 @@ import org.testng.ITestListener; import org.testng.ITestNGMethod; import org.testng.ITestResult; +import org.testng.xml.XmlSuite; + +abstract class DefaultListener implements IClassListener, ITestListener, IConfigurationListener, IAlterSuiteListener { -abstract class DefaultListener implements IClassListener, ITestListener, IConfigurationListener { + @Override + public void alter(List suites) { + } @Override public void onBeforeClass(ITestClass testClass) { diff --git a/src/main/java/org/junit/support/testng/engine/LoggingListener.java b/src/main/java/org/junit/support/testng/engine/LoggingListener.java index 739a9ae..ab9e3fc 100644 --- a/src/main/java/org/junit/support/testng/engine/LoggingListener.java +++ b/src/main/java/org/junit/support/testng/engine/LoggingListener.java @@ -10,12 +10,14 @@ package org.junit.support.testng.engine; +import java.util.List; import java.util.logging.Logger; import org.testng.ITestClass; import org.testng.ITestContext; import org.testng.ITestNGMethod; import org.testng.ITestResult; +import org.testng.xml.XmlSuite; class LoggingListener extends DefaultListener { @@ -25,6 +27,11 @@ class LoggingListener extends DefaultListener { private LoggingListener() { } + @Override + public void alter(List suites) { + LOGGER.fine(() -> "alter: " + suites); + } + @Override public void onBeforeClass(ITestClass testClass) { LOGGER.fine(() -> "onBeforeClass: " + testClass); diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index 257824b..2d0fca1 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -107,14 +107,16 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId *

* Supports the following configuration parameters: *

+ *
{@code testng.allowReturnValues} (file path)
+ *
whether methods with return values should be considered test methods (default: {@code false})
+ *
{@code testng.listeners} (comma-separated list of fully-qualified class names)
+ *
custom listeners that should be registered when executing tests (default: {@code ""})
*
{@code testng.outputDirectory} (file path)
- *
the output directory for reports (default: "test-output")
+ *
the output directory for reports (default: {@code "test-output"})
*
{@code testng.useDefaultListeners} (boolean)
*
whether TestNG's default report generating listeners should be used (default: {@code false})
- *
{@code testng.listeners} (comma-separated list of fully-qualified class names)
- *
custom listeners that should be registered when executing tests (default: none)
*
{@code testng.verbose} (integer)
- *
TestNG's level of verbosity (default: 0)
+ *
TestNG's level of verbosity (default: {@code 0})
*
*

* The implementation configures TestNG as if the discovered methods were specified on the @@ -153,6 +155,7 @@ private ExecutionListener createExecutionListener(EngineExecutionListener listen private void configureAndRun(TestNG testNG, Phase phase, ConfigurationParameters configurationParameters, ITestNGListener listener) { phase.configure(testNG, configurationParameters); + testNG.addListener(new ConfiguringListener(configurationParameters)); testNG.addListener(listener); testNG.run(); } diff --git a/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java index 601609a..8c4c7df 100644 --- a/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java @@ -37,6 +37,7 @@ import example.basics.InheritingSubClassTestCase; import example.basics.ParallelExecutionTestCase; import example.basics.RetriedTestCase; +import example.basics.ReturnValuesTestCase; import example.basics.SimpleTestCase; import example.basics.SuccessPercentageTestCase; import example.basics.TimeoutTestCase; @@ -310,9 +311,26 @@ void registersCustomListeners() { var results = testNGEngine() // .selectors(selectClass(testClass)) // - .configurationParameter("testng.listeners", SystemPropertyProvidingListener.class.getName()).execute(); + .configurationParameter("testng.listeners", SystemPropertyProvidingListener.class.getName()) // + .execute(); - results.allEvents().debug().assertEventsMatchLooselyInOrder( // + results.allEvents().assertEventsMatchLooselyInOrder( // + event(testClass(testClass), started()), // + event(test("method:test()"), started()), // + event(test("method:test()"), finishedSuccessfully()), // + event(testClass(testClass), finishedSuccessfully())); + } + + @Test + void executesTestMethodsWithReturnValuesWhenEnabledViaConfigurationParameter() { + var testClass = ReturnValuesTestCase.class; + + var results = testNGEngine() // + .selectors(selectClass(testClass)) // + .configurationParameter("testng.allowReturnValues", "true") // + .execute(); + + results.allEvents().assertEventsMatchLooselyInOrder( // event(testClass(testClass), started()), // event(test("method:test()"), started()), // event(test("method:test()"), finishedSuccessfully()), // diff --git a/src/testFixtures/java/example/basics/ReturnValuesTestCase.java b/src/testFixtures/java/example/basics/ReturnValuesTestCase.java new file mode 100644 index 0000000..1784ca4 --- /dev/null +++ b/src/testFixtures/java/example/basics/ReturnValuesTestCase.java @@ -0,0 +1,21 @@ +/* + * Copyright 2021 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package example.basics; + +import org.testng.annotations.Test; + +public class ReturnValuesTestCase { + + @Test + public String test() { + return "some bogus return value"; + } +} From cfc52702b1666bb7f84418bfd825e2acbc3ce02e Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sat, 17 Jul 2021 13:33:10 +0200 Subject: [PATCH 02/12] Move configuration parameter-specific tests to separate test class --- build.gradle.kts | 4 +- ...nfigurationParametersIntegrationTests.java | 59 +++++++++++++++++++ .../engine/ReportingIntegrationTests.java | 34 ----------- .../ReturnValuesTestCase.java | 2 +- .../SystemPropertyProvidingListener.java | 2 +- .../SystemPropertyReadingTestCase.java | 4 +- 6 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java rename src/testFixtures/java/example/{basics => configparams}/ReturnValuesTestCase.java (93%) rename src/testFixtures/java/example/{listeners => configparams}/SystemPropertyProvidingListener.java (96%) rename src/testFixtures/java/example/{listeners => configparams}/SystemPropertyReadingTestCase.java (83%) diff --git a/build.gradle.kts b/build.gradle.kts index 2682bd0..7aeb2ee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -153,7 +153,7 @@ tasks { classpath = configuration + sourceSets.testFixtures.get().output testClassesDirs = sourceSets.testFixtures.get().output useTestNG { - listeners.add("example.listeners.SystemPropertyProvidingListener") + listeners.add("example.configparams.SystemPropertyProvidingListener") } } register("testFixturesJUnitPlatform_${version.suffix}") { @@ -163,7 +163,7 @@ tasks { useJUnitPlatform { includeEngines("testng") } - systemProperty("testng.listeners", "example.listeners.SystemPropertyProvidingListener") + systemProperty("testng.listeners", "example.configparams.SystemPropertyProvidingListener") testLogging { events = EnumSet.allOf(TestLogEvent::class.java) } diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java new file mode 100644 index 0000000..bf12b4c --- /dev/null +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -0,0 +1,59 @@ +/* + * Copyright 2021 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package org.junit.support.testng.engine; + +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; +import static org.junit.platform.testkit.engine.EventConditions.event; +import static org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully; +import static org.junit.platform.testkit.engine.EventConditions.started; +import static org.junit.platform.testkit.engine.EventConditions.test; + +import example.configparams.ReturnValuesTestCase; +import example.configparams.SystemPropertyProvidingListener; +import example.configparams.SystemPropertyReadingTestCase; + +import org.junit.jupiter.api.Test; + +class ConfigurationParametersIntegrationTests extends AbstractIntegrationTests { + + @Test + void registersCustomListeners() { + var testClass = SystemPropertyReadingTestCase.class; + + var results = testNGEngine() // + .selectors(selectClass(testClass)) // + .configurationParameter("testng.listeners", SystemPropertyProvidingListener.class.getName()) // + .execute(); + + results.allEvents().assertEventsMatchLooselyInOrder( // + event(testClass(testClass), started()), // + event(test("method:test()"), started()), // + event(test("method:test()"), finishedSuccessfully()), // + event(testClass(testClass), finishedSuccessfully())); + } + + @Test + void executesTestMethodsWithReturnValuesWhenEnabledViaConfigurationParameter() { + var testClass = ReturnValuesTestCase.class; + + var results = testNGEngine() // + .selectors(selectClass(testClass)) // + .configurationParameter("testng.allowReturnValues", "true") // + .execute(); + + results.allEvents().assertEventsMatchLooselyInOrder( // + event(testClass(testClass), started()), // + event(test("method:test()"), started()), // + event(test("method:test()"), finishedSuccessfully()), // + event(testClass(testClass), finishedSuccessfully())); + } + +} diff --git a/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java index 8c4c7df..7db12e2 100644 --- a/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java @@ -37,14 +37,11 @@ import example.basics.InheritingSubClassTestCase; import example.basics.ParallelExecutionTestCase; import example.basics.RetriedTestCase; -import example.basics.ReturnValuesTestCase; import example.basics.SimpleTestCase; import example.basics.SuccessPercentageTestCase; import example.basics.TimeoutTestCase; import example.configuration.FailingBeforeClassConfigurationMethodTestCase; import example.dataproviders.DataProviderMethodTestCase; -import example.listeners.SystemPropertyProvidingListener; -import example.listeners.SystemPropertyReadingTestCase; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -305,35 +302,4 @@ void reportsParallelInvocations() { event(testClass(testClass), finishedSuccessfully())); } - @Test - void registersCustomListeners() { - var testClass = SystemPropertyReadingTestCase.class; - - var results = testNGEngine() // - .selectors(selectClass(testClass)) // - .configurationParameter("testng.listeners", SystemPropertyProvidingListener.class.getName()) // - .execute(); - - results.allEvents().assertEventsMatchLooselyInOrder( // - event(testClass(testClass), started()), // - event(test("method:test()"), started()), // - event(test("method:test()"), finishedSuccessfully()), // - event(testClass(testClass), finishedSuccessfully())); - } - - @Test - void executesTestMethodsWithReturnValuesWhenEnabledViaConfigurationParameter() { - var testClass = ReturnValuesTestCase.class; - - var results = testNGEngine() // - .selectors(selectClass(testClass)) // - .configurationParameter("testng.allowReturnValues", "true") // - .execute(); - - results.allEvents().assertEventsMatchLooselyInOrder( // - event(testClass(testClass), started()), // - event(test("method:test()"), started()), // - event(test("method:test()"), finishedSuccessfully()), // - event(testClass(testClass), finishedSuccessfully())); - } } diff --git a/src/testFixtures/java/example/basics/ReturnValuesTestCase.java b/src/testFixtures/java/example/configparams/ReturnValuesTestCase.java similarity index 93% rename from src/testFixtures/java/example/basics/ReturnValuesTestCase.java rename to src/testFixtures/java/example/configparams/ReturnValuesTestCase.java index 1784ca4..d257bcf 100644 --- a/src/testFixtures/java/example/basics/ReturnValuesTestCase.java +++ b/src/testFixtures/java/example/configparams/ReturnValuesTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.basics; +package example.configparams; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/listeners/SystemPropertyProvidingListener.java b/src/testFixtures/java/example/configparams/SystemPropertyProvidingListener.java similarity index 96% rename from src/testFixtures/java/example/listeners/SystemPropertyProvidingListener.java rename to src/testFixtures/java/example/configparams/SystemPropertyProvidingListener.java index 972be78..9fe1d18 100644 --- a/src/testFixtures/java/example/listeners/SystemPropertyProvidingListener.java +++ b/src/testFixtures/java/example/configparams/SystemPropertyProvidingListener.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.listeners; +package example.configparams; import org.testng.IClassListener; import org.testng.ITestClass; diff --git a/src/testFixtures/java/example/listeners/SystemPropertyReadingTestCase.java b/src/testFixtures/java/example/configparams/SystemPropertyReadingTestCase.java similarity index 83% rename from src/testFixtures/java/example/listeners/SystemPropertyReadingTestCase.java rename to src/testFixtures/java/example/configparams/SystemPropertyReadingTestCase.java index a5cad97..5b72c00 100644 --- a/src/testFixtures/java/example/listeners/SystemPropertyReadingTestCase.java +++ b/src/testFixtures/java/example/configparams/SystemPropertyReadingTestCase.java @@ -8,9 +8,9 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.listeners; +package example.configparams; -import static example.listeners.SystemPropertyProvidingListener.SYSTEM_PROPERTY_KEY; +import static example.configparams.SystemPropertyProvidingListener.SYSTEM_PROPERTY_KEY; import static org.testng.Assert.assertEquals; import org.testng.annotations.Test; From 219e44efbbe356866b0b45e0e60335b5f93df59e Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sat, 17 Jul 2021 13:49:15 +0200 Subject: [PATCH 03/12] Add testng.preserveOrder configuration parameter --- README.adoc | 3 +++ .../testng/engine/TestNGTestEngine.java | 9 +++++++ ...nfigurationParametersIntegrationTests.java | 22 ++++++++++++++++ .../configparams/PreserveOrderTestCase.java | 25 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/testFixtures/java/example/configparams/PreserveOrderTestCase.java diff --git a/README.adoc b/README.adoc index adeb51d..3ff2714 100644 --- a/README.adoc +++ b/README.adoc @@ -136,6 +136,9 @@ custom listeners that should be registered when executing tests (default: `""`) `testng.outputDirectory` (file path):: the output directory for reports (default: `"test-output"`) + +`testng.preserveOrder` (boolean):: +whether classes and methods should be run in a predictable order (default: `true`) ++ `testng.useDefaultListeners` (boolean):: whether TestNG's default report generating listeners should be used (default: `false`) + diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index 2d0fca1..acbf761 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -109,12 +109,19 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId *

*
{@code testng.allowReturnValues} (file path)
*
whether methods with return values should be considered test methods (default: {@code false})
+ * *
{@code testng.listeners} (comma-separated list of fully-qualified class names)
*
custom listeners that should be registered when executing tests (default: {@code ""})
+ * *
{@code testng.outputDirectory} (file path)
*
the output directory for reports (default: {@code "test-output"})
+ * + *
{@code testng.preserveOrder} (boolean)
+ *
whether classes and methods should be run in a predictable order (default: {@code true})
+ * *
{@code testng.useDefaultListeners} (boolean)
*
whether TestNG's default report generating listeners should be used (default: {@code false})
+ * *
{@code testng.verbose} (integer)
*
TestNG's level of verbosity (default: {@code 0})
*
@@ -228,6 +235,8 @@ void configure(TestNG testNG, ConfigurationParameters config) { return (ITestNGListener) ReflectionSupport.newInstance(listenerClass); }) // .forEach(testNG::addListener)); + config.getBoolean("testng.preserveOrder") // + .ifPresent(testNG::setPreserveOrder); } }; diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java index bf12b4c..657e4c7 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -13,14 +13,18 @@ import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; import static org.junit.platform.testkit.engine.EventConditions.event; import static org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully; +import static org.junit.platform.testkit.engine.EventConditions.finishedWithFailure; import static org.junit.platform.testkit.engine.EventConditions.started; import static org.junit.platform.testkit.engine.EventConditions.test; +import example.configparams.PreserveOrderTestCase; import example.configparams.ReturnValuesTestCase; import example.configparams.SystemPropertyProvidingListener; import example.configparams.SystemPropertyReadingTestCase; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; class ConfigurationParametersIntegrationTests extends AbstractIntegrationTests { @@ -56,4 +60,22 @@ void executesTestMethodsWithReturnValuesWhenEnabledViaConfigurationParameter() { event(testClass(testClass), finishedSuccessfully())); } + @ParameterizedTest + @ValueSource(booleans = { true, false }) + void configuresPreserveOrderOnXmlTest(boolean preserveOrder) { + var testClass = PreserveOrderTestCase.class; + + var results = testNGEngine() // + .selectors(selectClass(testClass)) // + .configurationParameter("testng.preserveOrder", String.valueOf(preserveOrder)) // + .execute(); + + results.allEvents().assertEventsMatchLooselyInOrder( // + event(testClass(testClass), started()), // + event(test("method:test(org.testng.ITestContext)"), started()), // + event(test("method:test(org.testng.ITestContext)"), + preserveOrder ? finishedSuccessfully() : finishedWithFailure()), // + event(testClass(testClass), finishedSuccessfully())); + } + } diff --git a/src/testFixtures/java/example/configparams/PreserveOrderTestCase.java b/src/testFixtures/java/example/configparams/PreserveOrderTestCase.java new file mode 100644 index 0000000..a2b36f9 --- /dev/null +++ b/src/testFixtures/java/example/configparams/PreserveOrderTestCase.java @@ -0,0 +1,25 @@ +/* + * Copyright 2021 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package example.configparams; + +import static org.testng.Assert.assertTrue; + +import org.testng.ITestContext; +import org.testng.annotations.Test; + +public class PreserveOrderTestCase { + + @Test + public void test(ITestContext context) { + assertTrue(context.getSuite().getXmlSuite().getPreserveOrder()); + assertTrue(context.getCurrentXmlTest().getPreserveOrder()); + } +} From bf9c9337ae397d5cf1c27c991292bbbaee659d33 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sat, 17 Jul 2021 17:15:26 +0200 Subject: [PATCH 04/12] Add testng.parallel configuration parameter --- README.adoc | 3 ++ .../testng/engine/TestNGTestEngine.java | 7 ++++ ...nfigurationParametersIntegrationTests.java | 12 ++++++ .../configparams/ParallelMethodsTestCase.java | 38 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java diff --git a/README.adoc b/README.adoc index 3ff2714..a13e135 100644 --- a/README.adoc +++ b/README.adoc @@ -136,6 +136,9 @@ custom listeners that should be registered when executing tests (default: `""`) `testng.outputDirectory` (file path):: the output directory for reports (default: `"test-output"`) + +`testng.parallel` (methods|tests|classes|instances|none):: +TestNG's parallel execution mode for running tests in separate threads (default: `"none"`) ++ `testng.preserveOrder` (boolean):: whether classes and methods should be run in a predictable order (default: `true`) + diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index acbf761..3951769 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -28,6 +28,7 @@ import org.testng.CommandLineArgs; import org.testng.ITestNGListener; import org.testng.TestNG; +import org.testng.xml.XmlSuite.ParallelMode; /** * The TestNG {@link TestEngine} for running TestNG tests on the JUnit Platform. @@ -116,6 +117,9 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId *
{@code testng.outputDirectory} (file path)
*
the output directory for reports (default: {@code "test-output"})
* + *
{@code testng.parallel} (methods|tests|classes|instances|none)
+ *
TestNG's parallel execution mode for running tests in separate threads (default: {@code "none"})
+ * *
{@code testng.preserveOrder} (boolean)
*
whether classes and methods should be run in a predictable order (default: {@code true})
* @@ -237,6 +241,9 @@ void configure(TestNG testNG, ConfigurationParameters config) { .forEach(testNG::addListener)); config.getBoolean("testng.preserveOrder") // .ifPresent(testNG::setPreserveOrder); + config.get("testng.parallel") // + .map(ParallelMode::getValidParallel) // + .ifPresent(testNG::setParallel); } }; diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java index 657e4c7..07a60ab 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -17,6 +17,7 @@ import static org.junit.platform.testkit.engine.EventConditions.started; import static org.junit.platform.testkit.engine.EventConditions.test; +import example.configparams.ParallelMethodsTestCase; import example.configparams.PreserveOrderTestCase; import example.configparams.ReturnValuesTestCase; import example.configparams.SystemPropertyProvidingListener; @@ -78,4 +79,15 @@ void configuresPreserveOrderOnXmlTest(boolean preserveOrder) { event(testClass(testClass), finishedSuccessfully())); } + @Test + void configuresParallelMode() { + var testClass = ParallelMethodsTestCase.class; + + var results = testNGEngine() // + .selectors(selectClass(testClass)) // + .configurationParameter("testng.parallel", "methods") // + .execute(); + + results.testEvents().debug().assertStatistics(stats -> stats.succeeded(2)); + } } diff --git a/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java b/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java new file mode 100644 index 0000000..62faf7c --- /dev/null +++ b/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java @@ -0,0 +1,38 @@ +/* + * Copyright 2021 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package example.configparams; + +import static org.testng.Assert.assertTrue; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.testng.annotations.Test; + +public class ParallelMethodsTestCase { + + final CountDownLatch latch = new CountDownLatch(2); + + @Test + public void a() throws Exception { + countDownAndAwait(); + } + + @Test + public void b() throws Exception { + countDownAndAwait(); + } + + private void countDownAndAwait() throws InterruptedException { + latch.countDown(); + assertTrue(latch.await(5, TimeUnit.SECONDS)); + } +} From 8e65670f7a8be42d688c69eb1f4604e28c78f834 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sat, 17 Jul 2021 19:16:26 +0200 Subject: [PATCH 05/12] Make formatting consistent --- .../java/org/junit/support/testng/engine/TestNGTestEngine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index 3951769..0ecfba7 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -226,7 +226,8 @@ void configure(TestNG testNG, ConfigurationParameters config) { testNG.addListener(LoggingListener.INSTANCE); testNG.setVerbose(config.get("testng.verbose", Integer::valueOf).orElse(0)); testNG.setUseDefaultListeners(config.getBoolean("testng.useDefaultListeners").orElse(false)); - config.get("testng.outputDirectory").ifPresent(testNG::setOutputDirectory); + config.get("testng.outputDirectory") // + .ifPresent(testNG::setOutputDirectory); config.get("testng.listeners").ifPresent(listeners -> Arrays.stream(listeners.split(",")) // .map(ReflectionSupport::tryToLoadClass) // .map(result -> result.getOrThrow( From 706834d4d270b14ba99c71be9d5bc0be24f8c923 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sat, 17 Jul 2021 19:39:13 +0200 Subject: [PATCH 06/12] Add testng.threadCount configuration parameter --- README.adoc | 21 +++++++++++------ .../testng/engine/TestNGTestEngine.java | 23 ++++++++++++------- ...nfigurationParametersIntegrationTests.java | 13 +++++++++++ .../configparams/ParallelMethodsTestCase.java | 4 ++-- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/README.adoc b/README.adoc index a13e135..54e6352 100644 --- a/README.adoc +++ b/README.adoc @@ -125,23 +125,30 @@ The engine requires at least JUnit Platform 1.5.x. === Configuration Parameters -The following JUnit Platform https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params[configuration parameters] are supported: +The following JUnit Platform https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params[configuration parameters] are supported. + +==== Execution `testng.allowReturnValues` (boolean):: whether methods with return values should be considered test methods (default: `false`) + -`testng.listeners` (comma-separated list of fully-qualified class names):: -custom listeners that should be registered when executing tests (default: `""`) -+ -`testng.outputDirectory` (file path):: -the output directory for reports (default: `"test-output"`) -+ `testng.parallel` (methods|tests|classes|instances|none):: TestNG's parallel execution mode for running tests in separate threads (default: `"none"`) + `testng.preserveOrder` (boolean):: whether classes and methods should be run in a predictable order (default: `true`) + +`testng.threadCount` (integer):: +default maximum number of threads to use for running tests in parallel, if enabled (default: `5`) + +==== Reporting + +`testng.listeners` (comma-separated list of fully-qualified class names):: +custom listeners that should be registered when executing tests (default: `""`) ++ +`testng.outputDirectory` (file path):: +the output directory for reports (default: `"test-output"`) ++ `testng.useDefaultListeners` (boolean):: whether TestNG's default report generating listeners should be used (default: `false`) + diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index 0ecfba7..fa61923 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -107,22 +107,28 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId * Execute the previously discovered TestNG tests in the supplied {@linkplain ExecutionRequest request}. *

* Supports the following configuration parameters: + *

Execution

*
*
{@code testng.allowReturnValues} (file path)
*
whether methods with return values should be considered test methods (default: {@code false})
* - *
{@code testng.listeners} (comma-separated list of fully-qualified class names)
- *
custom listeners that should be registered when executing tests (default: {@code ""})
- * - *
{@code testng.outputDirectory} (file path)
- *
the output directory for reports (default: {@code "test-output"})
- * *
{@code testng.parallel} (methods|tests|classes|instances|none)
*
TestNG's parallel execution mode for running tests in separate threads (default: {@code "none"})
* *
{@code testng.preserveOrder} (boolean)
*
whether classes and methods should be run in a predictable order (default: {@code true})
* + *
{@code testng.threadCount} (boolean)
+ *
default maximum number of threads to use for running tests in parallel, if enabled (default: {@code 5})
+ *
+ *

Reporting

+ *
+ *
{@code testng.listeners} (comma-separated list of fully-qualified class names)
+ *
custom listeners that should be registered when executing tests (default: {@code ""})
+ * + *
{@code testng.outputDirectory} (file path)
+ *
the output directory for reports (default: {@code "test-output"})
+ * *
{@code testng.useDefaultListeners} (boolean)
*
whether TestNG's default report generating listeners should be used (default: {@code false})
* @@ -242,9 +248,10 @@ void configure(TestNG testNG, ConfigurationParameters config) { .forEach(testNG::addListener)); config.getBoolean("testng.preserveOrder") // .ifPresent(testNG::setPreserveOrder); - config.get("testng.parallel") // - .map(ParallelMode::getValidParallel) // + config.get("testng.parallel", ParallelMode::getValidParallel) // .ifPresent(testNG::setParallel); + config.get("testng.threadCount", Integer::parseInt) // + .ifPresent(testNG::setThreadCount); } }; diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java index 07a60ab..f2431ce 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -90,4 +90,17 @@ void configuresParallelMode() { results.testEvents().debug().assertStatistics(stats -> stats.succeeded(2)); } + + @Test + void configuresThreadCount() { + var testClass = ParallelMethodsTestCase.class; + + var results = testNGEngine() // + .selectors(selectClass(testClass)) // + .configurationParameter("testng.parallel", "methods") // + .configurationParameter("testng.threadCount", "1") // + .execute(); + + results.testEvents().debug().assertStatistics(stats -> stats.succeeded(1).failed(1)); + } } diff --git a/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java b/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java index 62faf7c..c81eb0a 100644 --- a/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java +++ b/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java @@ -10,10 +10,10 @@ package example.configparams; +import static java.util.concurrent.TimeUnit.SECONDS; import static org.testng.Assert.assertTrue; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import org.testng.annotations.Test; @@ -33,6 +33,6 @@ public void b() throws Exception { private void countDownAndAwait() throws InterruptedException { latch.countDown(); - assertTrue(latch.await(5, TimeUnit.SECONDS)); + assertTrue(latch.await(1, SECONDS)); } } From 9c1916c34eb3d5992cc925f0f794095dde072291 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sun, 18 Jul 2021 12:33:19 +0200 Subject: [PATCH 07/12] Add testng.dataProviderThreadCount configuration parameter --- README.adoc | 5 +- .../testng/engine/TestNGTestEngine.java | 8 +++- ...nfigurationParametersIntegrationTests.java | 14 ++++++ .../DataProviderThreadCountTestCase.java | 47 +++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java diff --git a/README.adoc b/README.adoc index 54e6352..952a816 100644 --- a/README.adoc +++ b/README.adoc @@ -132,6 +132,9 @@ The following JUnit Platform https://junit.org/junit5/docs/current/user-guide/#r `testng.allowReturnValues` (boolean):: whether methods with return values should be considered test methods (default: `false`) + +`testng.dataProviderThreadCount` (integer):: +maximum number of threads to use for running data providers in parallel, if enabled via `@DataProvider(parallel = true)` (default: `10`) ++ `testng.parallel` (methods|tests|classes|instances|none):: TestNG's parallel execution mode for running tests in separate threads (default: `"none"`) + @@ -139,7 +142,7 @@ TestNG's parallel execution mode for running tests in separate threads (default: whether classes and methods should be run in a predictable order (default: `true`) + `testng.threadCount` (integer):: -default maximum number of threads to use for running tests in parallel, if enabled (default: `5`) +maximum number of threads for running tests in parallel, if enabled via `testng.parallel` (default: `5`) ==== Reporting diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index fa61923..0f97b97 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -28,6 +28,7 @@ import org.testng.CommandLineArgs; import org.testng.ITestNGListener; import org.testng.TestNG; +import org.testng.annotations.DataProvider; import org.testng.xml.XmlSuite.ParallelMode; /** @@ -112,6 +113,9 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId *
{@code testng.allowReturnValues} (file path)
*
whether methods with return values should be considered test methods (default: {@code false})
* + *
{@code testng.dataProviderThreadCount} (file path)
+ *
maximum number of threads to use for running data providers in parallel, if enabled via {@link DataProvider#parallel()} (default: {@code 10})
+ * *
{@code testng.parallel} (methods|tests|classes|instances|none)
*
TestNG's parallel execution mode for running tests in separate threads (default: {@code "none"})
* @@ -119,7 +123,7 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId *
whether classes and methods should be run in a predictable order (default: {@code true})
* *
{@code testng.threadCount} (boolean)
- *
default maximum number of threads to use for running tests in parallel, if enabled (default: {@code 5})
+ *
maximum number of threads for running tests in parallel, if enabled via {@code testng.parallel} (default: {@code 5})
*
*

Reporting

*
@@ -252,6 +256,8 @@ void configure(TestNG testNG, ConfigurationParameters config) { .ifPresent(testNG::setParallel); config.get("testng.threadCount", Integer::parseInt) // .ifPresent(testNG::setThreadCount); + config.get("testng.dataProviderThreadCount", Integer::parseInt) // + .ifPresent(testNG::setDataProviderThreadCount); } }; diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java index f2431ce..58654ea 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -17,6 +17,7 @@ import static org.junit.platform.testkit.engine.EventConditions.started; import static org.junit.platform.testkit.engine.EventConditions.test; +import example.configparams.DataProviderThreadCountTestCase; import example.configparams.ParallelMethodsTestCase; import example.configparams.PreserveOrderTestCase; import example.configparams.ReturnValuesTestCase; @@ -103,4 +104,17 @@ void configuresThreadCount() { results.testEvents().debug().assertStatistics(stats -> stats.succeeded(1).failed(1)); } + + @Test + void configuresDataProviderThreadCount() { + var testClass = DataProviderThreadCountTestCase.class; + var numInvocations = DataProviderThreadCountTestCase.NUM_INVOCATIONS; + + var results = testNGEngine() // + .selectors(selectClass(testClass)) // + .configurationParameter("testng.dataProviderThreadCount", String.valueOf(numInvocations)) // + .execute(); + + results.testEvents().debug().assertStatistics(stats -> stats.succeeded(numInvocations)); + } } diff --git a/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java b/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java new file mode 100644 index 0000000..243d7d0 --- /dev/null +++ b/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java @@ -0,0 +1,47 @@ +/* + * Copyright 2021 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package example.configparams; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.testng.Assert.assertTrue; +import static org.testng.xml.XmlSuite.DEFAULT_DATA_PROVIDER_THREAD_COUNT; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.concurrent.CountDownLatch; +import java.util.stream.IntStream; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class DataProviderThreadCountTestCase { + + public static final int NUM_INVOCATIONS = DEFAULT_DATA_PROVIDER_THREAD_COUNT + 1; + + final CountDownLatch latch = new CountDownLatch(NUM_INVOCATIONS); + + @DataProvider(name = "numbers", parallel = true) + public static Iterator numbers() { + return IntStream.range(0, NUM_INVOCATIONS) // + .mapToObj(Arrays::asList) // + .map(Collection::toArray) // + .iterator(); + } + + @Test(dataProvider = "numbers") + public void test(Integer number) throws Exception { + System.out.println(Thread.currentThread().getName() + ": " + number); + latch.countDown(); + assertTrue(latch.await(1, SECONDS)); + } + +} From ab5b06c33282be9ef05ae581c6102aa8ffff5124 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Mon, 19 Jul 2021 08:40:28 +0200 Subject: [PATCH 08/12] Let TestNG parse and instantiate listeners --- .../testng/engine/TestNGTestEngine.java | 114 +++++++++--------- ...nfigurationParametersIntegrationTests.java | 7 +- .../testng/engine/TestNGTestEngineTest.java | 69 ----------- .../InvocationTrackingListener.java | 29 +++++ 4 files changed, 91 insertions(+), 128 deletions(-) delete mode 100644 src/test/java/org/junit/support/testng/engine/TestNGTestEngineTest.java create mode 100644 src/testFixtures/java/example/configparams/InvocationTrackingListener.java diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index 0f97b97..28bd609 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -10,13 +10,12 @@ package org.junit.support.testng.engine; +import static org.junit.support.testng.engine.TestNGTestEngine.Configurer.testClasses; +import static org.junit.support.testng.engine.TestNGTestEngine.Configurer.testMethods; import static org.testng.internal.RuntimeBehavior.TESTNG_MODE_DRYRUN; -import java.util.Arrays; import java.util.List; -import org.junit.platform.commons.JUnitException; -import org.junit.platform.commons.support.ReflectionSupport; import org.junit.platform.engine.ConfigurationParameters; import org.junit.platform.engine.EngineDiscoveryRequest; import org.junit.platform.engine.EngineExecutionListener; @@ -88,15 +87,13 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId DiscoveryListener listener = new DiscoveryListener(engineDescriptor); if (testClasses.length > 0) { - TestNG testNG = createTestNGForTestClasses(testClasses); withTemporarySystemProperty(TESTNG_MODE_DRYRUN, "true", - () -> configureAndRun(testNG, Phase.DISCOVERY, configurationParameters, listener)); + () -> configureAndRun(configurationParameters, listener, testClasses(testClasses), Phase.DISCOVERY)); } if (!methodNames.isEmpty()) { - TestNG testNG = createTestNGForTestMethods(methodNames); withTemporarySystemProperty(TESTNG_MODE_DRYRUN, "true", - () -> configureAndRun(testNG, Phase.DISCOVERY, configurationParameters, listener)); + () -> configureAndRun(configurationParameters, listener, testMethods(methodNames), Phase.DISCOVERY)); } listener.finalizeDiscovery(); @@ -159,49 +156,32 @@ public void execute(ExecutionRequest request) { TestNGEngineDescriptor engineDescriptor = (TestNGEngineDescriptor) request.getRootTestDescriptor(); listener.executionStarted(engineDescriptor); engineDescriptor.prepareExecution(); - ExecutionListener executionListener = createExecutionListener(listener, engineDescriptor); + ExecutionListener executionListener = new ExecutionListener(listener, engineDescriptor); List methodNames = engineDescriptor.getQualifiedMethodNames(); if (!methodNames.isEmpty()) { - configureAndRun(createTestNGForTestMethods(methodNames), Phase.EXECUTION, - request.getConfigurationParameters(), executionListener); + configureAndRun(request.getConfigurationParameters(), executionListener, testMethods(methodNames), + Phase.EXECUTION); } listener.executionFinished(engineDescriptor, executionListener.toEngineResult()); } - private ExecutionListener createExecutionListener(EngineExecutionListener listener, - TestNGEngineDescriptor engineDescriptor) { - return new ExecutionListener(listener, engineDescriptor); - } - - private void configureAndRun(TestNG testNG, Phase phase, ConfigurationParameters configurationParameters, - ITestNGListener listener) { - phase.configure(testNG, configurationParameters); + private static void configureAndRun(ConfigurationParameters configurationParameters, ITestNGListener listener, + Configurer... configurers) { + CommandLineArgs commandLineArgs = new CommandLineArgs(); + for (Configurer configurer : configurers) { + configurer.configure(commandLineArgs, configurationParameters); + } + ConfigurableTestNG testNG = new ConfigurableTestNG(); + testNG.configure(commandLineArgs); + for (Configurer configurer : configurers) { + configurer.configure(testNG, configurationParameters); + } + testNG.addListener(LoggingListener.INSTANCE); testNG.addListener(new ConfiguringListener(configurationParameters)); testNG.addListener(listener); testNG.run(); } - private TestNG createTestNGForTestClasses(Class[] testClasses) { - ConfigurableTestNG testNG = new ConfigurableTestNG(); - testNG.setTestClasses(testClasses); - return testNG; - } - - private TestNG createTestNGForTestMethods(List methodNames) { - ConfigurableTestNG testNG = new ConfigurableTestNG(); - if (!methodNames.isEmpty()) { - testNG.configure(createCommandLineArgs(methodNames)); - } - return testNG; - } - - private static CommandLineArgs createCommandLineArgs(List methodNames) { - CommandLineArgs commandLineArgs = new CommandLineArgs(); - commandLineArgs.useDefaultListeners = String.valueOf(false); - commandLineArgs.commandLineMethods = methodNames; - return commandLineArgs; - } - @SuppressWarnings("SameParameterValue") private static void withTemporarySystemProperty(String key, String value, Runnable action) { String originalValue = System.getProperty(key); @@ -219,12 +199,39 @@ private static void withTemporarySystemProperty(String key, String value, Runnab } } - enum Phase { + interface Configurer { + + static Configurer testClasses(Class[] testClasses) { + return new Configurer() { + @Override + public void configure(TestNG testNG, ConfigurationParameters config) { + testNG.setTestClasses(testClasses); + } + }; + } + + static Configurer testMethods(List methodNames) { + return new Configurer() { + @Override + public void configure(CommandLineArgs commandLineArgs, ConfigurationParameters config) { + commandLineArgs.commandLineMethods = methodNames; + } + }; + } + + default void configure(TestNG testNG, ConfigurationParameters config) { + } + + default void configure(CommandLineArgs commandLineArgs, ConfigurationParameters config) { + } + + } + + enum Phase implements Configurer { DISCOVERY { @Override - void configure(TestNG testNG, ConfigurationParameters config) { - testNG.addListener(LoggingListener.INSTANCE); + public void configure(TestNG testNG, ConfigurationParameters config) { testNG.setVerbose(0); testNG.setUseDefaultListeners(false); } @@ -232,24 +239,11 @@ void configure(TestNG testNG, ConfigurationParameters config) { EXECUTION { @Override - void configure(TestNG testNG, ConfigurationParameters config) { - testNG.addListener(LoggingListener.INSTANCE); + public void configure(TestNG testNG, ConfigurationParameters config) { testNG.setVerbose(config.get("testng.verbose", Integer::valueOf).orElse(0)); testNG.setUseDefaultListeners(config.getBoolean("testng.useDefaultListeners").orElse(false)); config.get("testng.outputDirectory") // .ifPresent(testNG::setOutputDirectory); - config.get("testng.listeners").ifPresent(listeners -> Arrays.stream(listeners.split(",")) // - .map(ReflectionSupport::tryToLoadClass) // - .map(result -> result.getOrThrow( - cause -> new JUnitException("Failed to load custom listener class", cause))) // - .map(listenerClass -> { - if (!ITestNGListener.class.isAssignableFrom(listenerClass)) { - throw new JUnitException("Custom listener class must implement " - + ITestNGListener.class.getName() + ": " + listenerClass.getName()); - } - return (ITestNGListener) ReflectionSupport.newInstance(listenerClass); - }) // - .forEach(testNG::addListener)); config.getBoolean("testng.preserveOrder") // .ifPresent(testNG::setPreserveOrder); config.get("testng.parallel", ParallelMode::getValidParallel) // @@ -259,9 +253,13 @@ void configure(TestNG testNG, ConfigurationParameters config) { config.get("testng.dataProviderThreadCount", Integer::parseInt) // .ifPresent(testNG::setDataProviderThreadCount); } - }; - abstract void configure(TestNG testNG, ConfigurationParameters config); + @Override + public void configure(CommandLineArgs commandLineArgs, ConfigurationParameters config) { + config.get("testng.listeners") // + .ifPresent(listeners -> commandLineArgs.listener = listeners); + } + }; } /** diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java index 58654ea..88e180f 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -10,6 +10,7 @@ package org.junit.support.testng.engine; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; import static org.junit.platform.testkit.engine.EventConditions.event; import static org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully; @@ -18,6 +19,7 @@ import static org.junit.platform.testkit.engine.EventConditions.test; import example.configparams.DataProviderThreadCountTestCase; +import example.configparams.InvocationTrackingListener; import example.configparams.ParallelMethodsTestCase; import example.configparams.PreserveOrderTestCase; import example.configparams.ReturnValuesTestCase; @@ -33,12 +35,15 @@ class ConfigurationParametersIntegrationTests extends AbstractIntegrationTests { @Test void registersCustomListeners() { var testClass = SystemPropertyReadingTestCase.class; + InvocationTrackingListener.INVOKED = false; var results = testNGEngine() // .selectors(selectClass(testClass)) // - .configurationParameter("testng.listeners", SystemPropertyProvidingListener.class.getName()) // + .configurationParameter("testng.listeners", SystemPropertyProvidingListener.class.getName() + " , " + + InvocationTrackingListener.class.getName()) // .execute(); + assertThat(InvocationTrackingListener.INVOKED).isTrue(); results.allEvents().assertEventsMatchLooselyInOrder( // event(testClass(testClass), started()), // event(test("method:test()"), started()), // diff --git a/src/test/java/org/junit/support/testng/engine/TestNGTestEngineTest.java b/src/test/java/org/junit/support/testng/engine/TestNGTestEngineTest.java deleted file mode 100644 index 06c087c..0000000 --- a/src/test/java/org/junit/support/testng/engine/TestNGTestEngineTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2021 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ - -package org.junit.support.testng.engine; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.when; -import static org.mockito.quality.Strictness.LENIENT; - -import java.util.Optional; - -import org.junit.jupiter.api.Test; -import org.junit.platform.engine.ConfigurationParameters; -import org.junit.support.testng.engine.TestNGTestEngine.Phase; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoSettings; -import org.testng.TestNG; - -@MockitoSettings(strictness = LENIENT) -public class TestNGTestEngineTest { - - TestNG testNG = new TestNG(); - - @Test - void configuresListenersFromConfigurationParameter(@Mock ConfigurationParameters configurationParameters) { - when(configurationParameters.get("testng.listeners")) // - .thenReturn(Optional.of(MyTestListener.class.getName() + " , " + AnotherTestListener.class.getName())); - - Phase.EXECUTION.configure(testNG, configurationParameters); - - assertThat(testNG.getTestListeners()) // - .hasAtLeastOneElementOfType(MyTestListener.class) // - .hasAtLeastOneElementOfType(AnotherTestListener.class); - } - - @Test - void throwsExceptionForMissingClasses(@Mock ConfigurationParameters configurationParameters) { - when(configurationParameters.get("testng.listeners")) // - .thenReturn(Optional.of("acme.MissingClass")); - - assertThatThrownBy(() -> Phase.EXECUTION.configure(testNG, configurationParameters)) // - .hasMessage("Failed to load custom listener class") // - .hasRootCauseExactlyInstanceOf(ClassNotFoundException.class) // - .hasRootCauseMessage("acme.MissingClass"); - } - - @Test - void throwsExceptionForClassesOfWrongType(@Mock ConfigurationParameters configurationParameters) { - when(configurationParameters.get("testng.listeners")) // - .thenReturn(Optional.of(Object.class.getName())); - - assertThatThrownBy(() -> Phase.EXECUTION.configure(testNG, configurationParameters)) // - .hasMessage("Custom listener class must implement org.testng.ITestNGListener: java.lang.Object"); - } - - static class MyTestListener extends DefaultListener { - } - - static class AnotherTestListener extends DefaultListener { - } -} diff --git a/src/testFixtures/java/example/configparams/InvocationTrackingListener.java b/src/testFixtures/java/example/configparams/InvocationTrackingListener.java new file mode 100644 index 0000000..b1d63b5 --- /dev/null +++ b/src/testFixtures/java/example/configparams/InvocationTrackingListener.java @@ -0,0 +1,29 @@ +/* + * Copyright 2021 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package example.configparams; + +import org.testng.IClassListener; +import org.testng.ITestClass; + +public class InvocationTrackingListener implements IClassListener { + + public static boolean INVOKED; + + @Override + public void onBeforeClass(ITestClass testClass) { + INVOKED = true; + } + + @Override + public void onAfterClass(ITestClass testClass) { + // do nothing + } +} From b98550cf3310786ae51843e29e7306e901ba1876 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Mon, 19 Jul 2021 16:22:05 +0200 Subject: [PATCH 09/12] Make docs clearer --- README.adoc | 18 +++++++++--------- .../testng/engine/TestNGTestEngine.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.adoc b/README.adoc index 952a816..9ab45ef 100644 --- a/README.adoc +++ b/README.adoc @@ -130,33 +130,33 @@ The following JUnit Platform https://junit.org/junit5/docs/current/user-guide/#r ==== Execution `testng.allowReturnValues` (boolean):: -whether methods with return values should be considered test methods (default: `false`) +whether methods annotated with `@Test` that have return values should be considered test methods (default: `false`; see https://testng.org/doc/documentation-main.html#test-methods[documentation]) + `testng.dataProviderThreadCount` (integer):: -maximum number of threads to use for running data providers in parallel, if enabled via `@DataProvider(parallel = true)` (default: `10`) +maximum number of threads to use for running data providers in parallel, if enabled via `@DataProvider(parallel = true)` (default: `10`; see https://testng.org/doc/documentation-main.html#parameters-dataproviders[documentation]) + `testng.parallel` (methods|tests|classes|instances|none):: -TestNG's parallel execution mode for running tests in separate threads (default: `"none"`) +TestNG's parallel execution mode for running tests in separate threads (default: `"none"`; see https://testng.org/doc/documentation-main.html#parallel-tests[documentation]) + `testng.preserveOrder` (boolean):: -whether classes and methods should be run in a predictable order (default: `true`) +whether classes and methods should be run in a predictable order (default: `true`; see https://testng.org/doc/documentation-main.html#testng-xml[documentation]) + `testng.threadCount` (integer):: -maximum number of threads for running tests in parallel, if enabled via `testng.parallel` (default: `5`) +maximum number of threads for running tests in parallel, if enabled via `testng.parallel` (default: `5`; see https://testng.org/doc/documentation-main.html#parallel-tests[documentation]) ==== Reporting `testng.listeners` (comma-separated list of fully-qualified class names):: -custom listeners that should be registered when executing tests (default: `""`) +custom listeners that should be registered when executing tests (default: `""`; see https://testng.org/doc/documentation-main.html#testng-listeners[documentation]) + `testng.outputDirectory` (file path):: -the output directory for reports (default: `"test-output"`) +the output directory for reports (default: `"test-output"`; see https://testng.org/doc/documentation-main.html#running-testng[documentation]) + `testng.useDefaultListeners` (boolean):: -whether TestNG's default report generating listeners should be used (default: `false`) +whether TestNG's default report generating listeners should be used (default: `false`; see https://testng.org/doc/documentation-main.html#running-testng[documentation]) + `testng.verbose` (integer):: -TestNG's level of verbosity (default: `0`) +TestNG's level of verbosity for console output (default: `0`) === Generating TestNG reports diff --git a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java index 28bd609..3cd62c5 100644 --- a/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java +++ b/src/main/java/org/junit/support/testng/engine/TestNGTestEngine.java @@ -108,7 +108,7 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId uniqueId *

Execution

*
*
{@code testng.allowReturnValues} (file path)
- *
whether methods with return values should be considered test methods (default: {@code false})
+ *
whether methods annotated with {@code @Test} that have return values should be considered test methods (default: {@code false})
* *
{@code testng.dataProviderThreadCount} (file path)
*
maximum number of threads to use for running data providers in parallel, if enabled via {@link DataProvider#parallel()} (default: {@code 10})
From 7c97972a54c2651f51bd6283806374be83a0c444 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Mon, 19 Jul 2021 16:22:16 +0200 Subject: [PATCH 10/12] Simplify data provider --- .../configparams/DataProviderThreadCountTestCase.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java b/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java index 243d7d0..b48bac1 100644 --- a/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java +++ b/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java @@ -14,8 +14,6 @@ import static org.testng.Assert.assertTrue; import static org.testng.xml.XmlSuite.DEFAULT_DATA_PROVIDER_THREAD_COUNT; -import java.util.Arrays; -import java.util.Collection; import java.util.Iterator; import java.util.concurrent.CountDownLatch; import java.util.stream.IntStream; @@ -32,8 +30,7 @@ public class DataProviderThreadCountTestCase { @DataProvider(name = "numbers", parallel = true) public static Iterator numbers() { return IntStream.range(0, NUM_INVOCATIONS) // - .mapToObj(Arrays::asList) // - .map(Collection::toArray) // + .mapToObj(i -> new Object[] { i }) // .iterator(); } From afaf87d94c9b58758594fe0f0b5335e43ad21086 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Mon, 19 Jul 2021 16:22:31 +0200 Subject: [PATCH 11/12] Use lower case for non-final static field --- .../engine/ConfigurationParametersIntegrationTests.java | 4 ++-- .../java/example/configparams/InvocationTrackingListener.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java index 88e180f..1122391 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -35,7 +35,7 @@ class ConfigurationParametersIntegrationTests extends AbstractIntegrationTests { @Test void registersCustomListeners() { var testClass = SystemPropertyReadingTestCase.class; - InvocationTrackingListener.INVOKED = false; + InvocationTrackingListener.invoked = false; var results = testNGEngine() // .selectors(selectClass(testClass)) // @@ -43,7 +43,7 @@ void registersCustomListeners() { + InvocationTrackingListener.class.getName()) // .execute(); - assertThat(InvocationTrackingListener.INVOKED).isTrue(); + assertThat(InvocationTrackingListener.invoked).isTrue(); results.allEvents().assertEventsMatchLooselyInOrder( // event(testClass(testClass), started()), // event(test("method:test()"), started()), // diff --git a/src/testFixtures/java/example/configparams/InvocationTrackingListener.java b/src/testFixtures/java/example/configparams/InvocationTrackingListener.java index b1d63b5..166112a 100644 --- a/src/testFixtures/java/example/configparams/InvocationTrackingListener.java +++ b/src/testFixtures/java/example/configparams/InvocationTrackingListener.java @@ -15,11 +15,11 @@ public class InvocationTrackingListener implements IClassListener { - public static boolean INVOKED; + public static boolean invoked; @Override public void onBeforeClass(ITestClass testClass) { - INVOKED = true; + invoked = true; } @Override From e11de25e226a34df4df275ad3324362e09474d3e Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Mon, 19 Jul 2021 17:08:35 +0200 Subject: [PATCH 12/12] Restructure example packages --- .../ConfigurationMethodIntegrationTests.java | 16 ++++++++-------- .../ConfigurationParametersIntegrationTests.java | 14 +++++++------- .../testng/engine/ReportingIntegrationTests.java | 2 +- ...ingAfterClassConfigurationMethodTestCase.java | 2 +- ...ngAfterMethodConfigurationMethodTestCase.java | 2 +- ...ingAfterSuiteConfigurationMethodTestCase.java | 2 +- ...lingAfterTestConfigurationMethodTestCase.java | 2 +- ...ngBeforeClassConfigurationMethodTestCase.java | 2 +- ...gBeforeMethodConfigurationMethodTestCase.java | 2 +- ...ngBeforeSuiteConfigurationMethodTestCase.java | 2 +- ...ingBeforeTestConfigurationMethodTestCase.java | 2 +- .../DataProviderThreadCountTestCase.java | 2 +- .../parameters}/InvocationTrackingListener.java | 2 +- .../parameters}/ParallelMethodsTestCase.java | 2 +- .../parameters}/PreserveOrderTestCase.java | 2 +- .../parameters}/ReturnValuesTestCase.java | 2 +- .../SystemPropertyProvidingListener.java | 2 +- .../SystemPropertyReadingTestCase.java | 6 +++--- 18 files changed, 33 insertions(+), 33 deletions(-) rename src/testFixtures/java/example/configuration/{ => methods}/FailingAfterClassConfigurationMethodTestCase.java (93%) rename src/testFixtures/java/example/configuration/{ => methods}/FailingAfterMethodConfigurationMethodTestCase.java (93%) rename src/testFixtures/java/example/configuration/{ => methods}/FailingAfterSuiteConfigurationMethodTestCase.java (93%) rename src/testFixtures/java/example/configuration/{ => methods}/FailingAfterTestConfigurationMethodTestCase.java (93%) rename src/testFixtures/java/example/configuration/{ => methods}/FailingBeforeClassConfigurationMethodTestCase.java (93%) rename src/testFixtures/java/example/configuration/{ => methods}/FailingBeforeMethodConfigurationMethodTestCase.java (94%) rename src/testFixtures/java/example/configuration/{ => methods}/FailingBeforeSuiteConfigurationMethodTestCase.java (93%) rename src/testFixtures/java/example/configuration/{ => methods}/FailingBeforeTestConfigurationMethodTestCase.java (93%) rename src/testFixtures/java/example/{configparams => configuration/parameters}/DataProviderThreadCountTestCase.java (96%) rename src/testFixtures/java/example/{configparams => configuration/parameters}/InvocationTrackingListener.java (93%) rename src/testFixtures/java/example/{configparams => configuration/parameters}/ParallelMethodsTestCase.java (95%) rename src/testFixtures/java/example/{configparams => configuration/parameters}/PreserveOrderTestCase.java (93%) rename src/testFixtures/java/example/{configparams => configuration/parameters}/ReturnValuesTestCase.java (91%) rename src/testFixtures/java/example/{configparams => configuration/parameters}/SystemPropertyProvidingListener.java (94%) rename src/testFixtures/java/example/{configparams => configuration/parameters}/SystemPropertyReadingTestCase.java (68%) diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationMethodIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationMethodIntegrationTests.java index 3a67cc3..c98797c 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationMethodIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationMethodIntegrationTests.java @@ -20,14 +20,14 @@ import static org.junit.platform.testkit.engine.EventConditions.test; import static org.junit.platform.testkit.engine.TestExecutionResultConditions.message; -import example.configuration.FailingAfterClassConfigurationMethodTestCase; -import example.configuration.FailingAfterMethodConfigurationMethodTestCase; -import example.configuration.FailingAfterSuiteConfigurationMethodTestCase; -import example.configuration.FailingAfterTestConfigurationMethodTestCase; -import example.configuration.FailingBeforeClassConfigurationMethodTestCase; -import example.configuration.FailingBeforeMethodConfigurationMethodTestCase; -import example.configuration.FailingBeforeSuiteConfigurationMethodTestCase; -import example.configuration.FailingBeforeTestConfigurationMethodTestCase; +import example.configuration.methods.FailingAfterClassConfigurationMethodTestCase; +import example.configuration.methods.FailingAfterMethodConfigurationMethodTestCase; +import example.configuration.methods.FailingAfterSuiteConfigurationMethodTestCase; +import example.configuration.methods.FailingAfterTestConfigurationMethodTestCase; +import example.configuration.methods.FailingBeforeClassConfigurationMethodTestCase; +import example.configuration.methods.FailingBeforeMethodConfigurationMethodTestCase; +import example.configuration.methods.FailingBeforeSuiteConfigurationMethodTestCase; +import example.configuration.methods.FailingBeforeTestConfigurationMethodTestCase; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java index 1122391..2e68adc 100644 --- a/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ConfigurationParametersIntegrationTests.java @@ -18,13 +18,13 @@ import static org.junit.platform.testkit.engine.EventConditions.started; import static org.junit.platform.testkit.engine.EventConditions.test; -import example.configparams.DataProviderThreadCountTestCase; -import example.configparams.InvocationTrackingListener; -import example.configparams.ParallelMethodsTestCase; -import example.configparams.PreserveOrderTestCase; -import example.configparams.ReturnValuesTestCase; -import example.configparams.SystemPropertyProvidingListener; -import example.configparams.SystemPropertyReadingTestCase; +import example.configuration.parameters.DataProviderThreadCountTestCase; +import example.configuration.parameters.InvocationTrackingListener; +import example.configuration.parameters.ParallelMethodsTestCase; +import example.configuration.parameters.PreserveOrderTestCase; +import example.configuration.parameters.ReturnValuesTestCase; +import example.configuration.parameters.SystemPropertyProvidingListener; +import example.configuration.parameters.SystemPropertyReadingTestCase; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java b/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java index 7db12e2..22cda48 100644 --- a/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java +++ b/src/test/java/org/junit/support/testng/engine/ReportingIntegrationTests.java @@ -40,7 +40,7 @@ import example.basics.SimpleTestCase; import example.basics.SuccessPercentageTestCase; import example.basics.TimeoutTestCase; -import example.configuration.FailingBeforeClassConfigurationMethodTestCase; +import example.configuration.methods.FailingBeforeClassConfigurationMethodTestCase; import example.dataproviders.DataProviderMethodTestCase; import org.junit.jupiter.api.Test; diff --git a/src/testFixtures/java/example/configuration/FailingAfterClassConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingAfterClassConfigurationMethodTestCase.java similarity index 93% rename from src/testFixtures/java/example/configuration/FailingAfterClassConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingAfterClassConfigurationMethodTestCase.java index d3bfcf5..8112465 100644 --- a/src/testFixtures/java/example/configuration/FailingAfterClassConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingAfterClassConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configuration/FailingAfterMethodConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingAfterMethodConfigurationMethodTestCase.java similarity index 93% rename from src/testFixtures/java/example/configuration/FailingAfterMethodConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingAfterMethodConfigurationMethodTestCase.java index cd80441..4a36fa8 100644 --- a/src/testFixtures/java/example/configuration/FailingAfterMethodConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingAfterMethodConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configuration/FailingAfterSuiteConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingAfterSuiteConfigurationMethodTestCase.java similarity index 93% rename from src/testFixtures/java/example/configuration/FailingAfterSuiteConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingAfterSuiteConfigurationMethodTestCase.java index c3cfaf7..4d6dcb6 100644 --- a/src/testFixtures/java/example/configuration/FailingAfterSuiteConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingAfterSuiteConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.AfterSuite; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configuration/FailingAfterTestConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingAfterTestConfigurationMethodTestCase.java similarity index 93% rename from src/testFixtures/java/example/configuration/FailingAfterTestConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingAfterTestConfigurationMethodTestCase.java index a5b7723..af3ea2e 100644 --- a/src/testFixtures/java/example/configuration/FailingAfterTestConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingAfterTestConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configuration/FailingBeforeClassConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingBeforeClassConfigurationMethodTestCase.java similarity index 93% rename from src/testFixtures/java/example/configuration/FailingBeforeClassConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingBeforeClassConfigurationMethodTestCase.java index 1d60189..c95bfc5 100644 --- a/src/testFixtures/java/example/configuration/FailingBeforeClassConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingBeforeClassConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configuration/FailingBeforeMethodConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingBeforeMethodConfigurationMethodTestCase.java similarity index 94% rename from src/testFixtures/java/example/configuration/FailingBeforeMethodConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingBeforeMethodConfigurationMethodTestCase.java index af766ec..c060460 100644 --- a/src/testFixtures/java/example/configuration/FailingBeforeMethodConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingBeforeMethodConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configuration/FailingBeforeSuiteConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingBeforeSuiteConfigurationMethodTestCase.java similarity index 93% rename from src/testFixtures/java/example/configuration/FailingBeforeSuiteConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingBeforeSuiteConfigurationMethodTestCase.java index 7fda35e..428fcc3 100644 --- a/src/testFixtures/java/example/configuration/FailingBeforeSuiteConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingBeforeSuiteConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configuration/FailingBeforeTestConfigurationMethodTestCase.java b/src/testFixtures/java/example/configuration/methods/FailingBeforeTestConfigurationMethodTestCase.java similarity index 93% rename from src/testFixtures/java/example/configuration/FailingBeforeTestConfigurationMethodTestCase.java rename to src/testFixtures/java/example/configuration/methods/FailingBeforeTestConfigurationMethodTestCase.java index 98f4d05..10fae62 100644 --- a/src/testFixtures/java/example/configuration/FailingBeforeTestConfigurationMethodTestCase.java +++ b/src/testFixtures/java/example/configuration/methods/FailingBeforeTestConfigurationMethodTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configuration; +package example.configuration.methods; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java b/src/testFixtures/java/example/configuration/parameters/DataProviderThreadCountTestCase.java similarity index 96% rename from src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java rename to src/testFixtures/java/example/configuration/parameters/DataProviderThreadCountTestCase.java index b48bac1..b11f41a 100644 --- a/src/testFixtures/java/example/configparams/DataProviderThreadCountTestCase.java +++ b/src/testFixtures/java/example/configuration/parameters/DataProviderThreadCountTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configparams; +package example.configuration.parameters; import static java.util.concurrent.TimeUnit.SECONDS; import static org.testng.Assert.assertTrue; diff --git a/src/testFixtures/java/example/configparams/InvocationTrackingListener.java b/src/testFixtures/java/example/configuration/parameters/InvocationTrackingListener.java similarity index 93% rename from src/testFixtures/java/example/configparams/InvocationTrackingListener.java rename to src/testFixtures/java/example/configuration/parameters/InvocationTrackingListener.java index 166112a..88f2ff4 100644 --- a/src/testFixtures/java/example/configparams/InvocationTrackingListener.java +++ b/src/testFixtures/java/example/configuration/parameters/InvocationTrackingListener.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configparams; +package example.configuration.parameters; import org.testng.IClassListener; import org.testng.ITestClass; diff --git a/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java b/src/testFixtures/java/example/configuration/parameters/ParallelMethodsTestCase.java similarity index 95% rename from src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java rename to src/testFixtures/java/example/configuration/parameters/ParallelMethodsTestCase.java index c81eb0a..bd877f7 100644 --- a/src/testFixtures/java/example/configparams/ParallelMethodsTestCase.java +++ b/src/testFixtures/java/example/configuration/parameters/ParallelMethodsTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configparams; +package example.configuration.parameters; import static java.util.concurrent.TimeUnit.SECONDS; import static org.testng.Assert.assertTrue; diff --git a/src/testFixtures/java/example/configparams/PreserveOrderTestCase.java b/src/testFixtures/java/example/configuration/parameters/PreserveOrderTestCase.java similarity index 93% rename from src/testFixtures/java/example/configparams/PreserveOrderTestCase.java rename to src/testFixtures/java/example/configuration/parameters/PreserveOrderTestCase.java index a2b36f9..209eb5e 100644 --- a/src/testFixtures/java/example/configparams/PreserveOrderTestCase.java +++ b/src/testFixtures/java/example/configuration/parameters/PreserveOrderTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configparams; +package example.configuration.parameters; import static org.testng.Assert.assertTrue; diff --git a/src/testFixtures/java/example/configparams/ReturnValuesTestCase.java b/src/testFixtures/java/example/configuration/parameters/ReturnValuesTestCase.java similarity index 91% rename from src/testFixtures/java/example/configparams/ReturnValuesTestCase.java rename to src/testFixtures/java/example/configuration/parameters/ReturnValuesTestCase.java index d257bcf..ad395bb 100644 --- a/src/testFixtures/java/example/configparams/ReturnValuesTestCase.java +++ b/src/testFixtures/java/example/configuration/parameters/ReturnValuesTestCase.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configparams; +package example.configuration.parameters; import org.testng.annotations.Test; diff --git a/src/testFixtures/java/example/configparams/SystemPropertyProvidingListener.java b/src/testFixtures/java/example/configuration/parameters/SystemPropertyProvidingListener.java similarity index 94% rename from src/testFixtures/java/example/configparams/SystemPropertyProvidingListener.java rename to src/testFixtures/java/example/configuration/parameters/SystemPropertyProvidingListener.java index 9fe1d18..57d247e 100644 --- a/src/testFixtures/java/example/configparams/SystemPropertyProvidingListener.java +++ b/src/testFixtures/java/example/configuration/parameters/SystemPropertyProvidingListener.java @@ -8,7 +8,7 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configparams; +package example.configuration.parameters; import org.testng.IClassListener; import org.testng.ITestClass; diff --git a/src/testFixtures/java/example/configparams/SystemPropertyReadingTestCase.java b/src/testFixtures/java/example/configuration/parameters/SystemPropertyReadingTestCase.java similarity index 68% rename from src/testFixtures/java/example/configparams/SystemPropertyReadingTestCase.java rename to src/testFixtures/java/example/configuration/parameters/SystemPropertyReadingTestCase.java index 5b72c00..fd52da2 100644 --- a/src/testFixtures/java/example/configparams/SystemPropertyReadingTestCase.java +++ b/src/testFixtures/java/example/configuration/parameters/SystemPropertyReadingTestCase.java @@ -8,9 +8,8 @@ * https://www.eclipse.org/legal/epl-v20.html */ -package example.configparams; +package example.configuration.parameters; -import static example.configparams.SystemPropertyProvidingListener.SYSTEM_PROPERTY_KEY; import static org.testng.Assert.assertEquals; import org.testng.annotations.Test; @@ -19,6 +18,7 @@ public class SystemPropertyReadingTestCase { @Test public void test() { - assertEquals(System.getProperty(SYSTEM_PROPERTY_KEY), SystemPropertyReadingTestCase.class.getName()); + assertEquals(System.getProperty(SystemPropertyProvidingListener.SYSTEM_PROPERTY_KEY), + SystemPropertyReadingTestCase.class.getName()); } }