Class TestNGTestEngine
- java.lang.Object
-
- org.junit.support.testng.engine.TestNGTestEngine
-
- All Implemented Interfaces:
org.junit.platform.engine.TestEngine
public class TestNGTestEngine extends java.lang.Object implements org.junit.platform.engine.TestEngine
The TestNGTestEngine
for running TestNG tests on the JUnit Platform.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TestNGTestEngine.ConfigurableTestNG
Needed to makeTestNGTestEngine.ConfigurableTestNG.configure(CommandLineArgs)
accessible.(package private) static interface
TestNGTestEngine.Configurer
(package private) static class
TestNGTestEngine.Phase
-
Field Summary
Fields Modifier and Type Field Description private static org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver<TestNGEngineDescriptor>
DISCOVERY_REQUEST_RESOLVER
-
Constructor Summary
Constructors Constructor Description TestNGTestEngine()
Create a new instance (typically called by the JUnit Platform via ServiceLoader).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
configureAndRun(org.junit.platform.engine.ConfigurationParameters configurationParameters, org.testng.ITestNGListener listener, TestNGTestEngine.Configurer... configurers)
org.junit.platform.engine.TestDescriptor
discover(org.junit.platform.engine.EngineDiscoveryRequest request, org.junit.platform.engine.UniqueId uniqueId)
Discover TestNG tests based on the supplied request.void
execute(org.junit.platform.engine.ExecutionRequest request)
Execute the previously discovered TestNG tests in the supplied request.java.lang.String
getId()
private static void
withTemporarySystemProperty(java.lang.String key, java.lang.String value, java.lang.Runnable action)
-
-
-
Field Detail
-
DISCOVERY_REQUEST_RESOLVER
private static final org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver<TestNGEngineDescriptor> DISCOVERY_REQUEST_RESOLVER
-
-
Method Detail
-
getId
public java.lang.String getId()
- Specified by:
getId
in interfaceorg.junit.platform.engine.TestEngine
-
discover
public org.junit.platform.engine.TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest request, org.junit.platform.engine.UniqueId uniqueId)
Discover TestNG tests based on the supplied request.Supports the following selectors:
ClasspathRootSelector
ClassSelector
MethodSelector
ModuleSelector
PackageSelector
UniqueIdSelector
Custom test suites specified via
testng.xml
files are not supported.Supports the following filters:
ClassNameFilter
PackageNameFilter
- Any post-discovery filter, e.g. for included/excluded tags
The implementation collects a list of potential test classes and method names and uses TestNG's dry-run mode to determine which of them are TestNG test classes and methods. Since TestNG can only run either classes or methods, it will be executed twice in the edge case that class and method selectors are part of the discovery request.
- Specified by:
discover
in interfaceorg.junit.platform.engine.TestEngine
-
execute
public void execute(org.junit.platform.engine.ExecutionRequest request)
Execute the previously discovered TestNG tests in the supplied request.Supports the following configuration parameters:
Execution
testng.allowReturnValues
(file path)- whether methods annotated with
@Test
that have return values should be considered test methods (default:false
) testng.dataProviderThreadCount
(file path)- maximum number of threads to use for running data providers in parallel, if enabled via
DataProvider.parallel()
(default:10
) 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
(boolean)- maximum number of threads for running tests in parallel, if enabled via
testng.parallel
(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
) testng.verbose
(integer)- TestNG's level of verbosity (default:
0
)
The implementation configures TestNG as if the discovered methods were specified on the command line.
Data providers test methods are reported as a nested structure, i.e. individual invocations are reported underneath the test methods along with their parameters:
└─ TestNG ✔ └─ DataProviderMethodTestCase ✔ └─ test(java.lang.String) ✔ ├─ [0] a ✔ └─ [1] b ✔
- Specified by:
execute
in interfaceorg.junit.platform.engine.TestEngine
-
configureAndRun
private static void configureAndRun(org.junit.platform.engine.ConfigurationParameters configurationParameters, org.testng.ITestNGListener listener, TestNGTestEngine.Configurer... configurers)
-
withTemporarySystemProperty
private static void withTemporarySystemProperty(java.lang.String key, java.lang.String value, java.lang.Runnable action)
-
-