Top Description Inners Constructors Methods
org.junit.platform.testkit.engine

public final Class EngineTestKit

extends Object
Class Inheritance
Annotations
@API
status:MAINTAINED
since:1.7
Static Imports
java.util.Collections.emptySet, .Collections.singleton, .Objects.requireNonNullElseGet, org.apiguardian.api.API.Status.DEPRECATED, .API.Status.EXPERIMENTAL, .API.Status.MAINTAINED, .API.Status.STABLE, org.junit.platform.engine.support.store.NamespacedHierarchicalStore.CloseAction.closeAutoCloseables

EngineTestKit provides support for discovering and executing tests for a given TestEngine and provides convenient access to the results.

For discovery, EngineDiscoveryResults provides access to the TestDescriptor of the engine and any DiscoveryIssues that were encountered.

For execution, EngineExecutionResults provides a fluent API to verify the expected results.

Since
1.4
See Also
engine(String), engine(TestEngine), discover(String, LauncherDiscoveryRequest), discover(TestEngine, LauncherDiscoveryRequest), execute(String, LauncherDiscoveryRequest), execute(TestEngine, LauncherDiscoveryRequest), EngineDiscoveryResults, EngineExecutionResults

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static EngineDiscoveryResults

Returns:

the results of the discovery
discover
(String
the ID of the TestEngine to use; must not be null or blank
engineId
,
LauncherDiscoveryRequest
the LauncherDiscoveryRequest to use
discoveryRequest
)

Discover tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.

The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

public static EngineDiscoveryResults

Returns:

the recorded EngineExecutionResults
discover
(TestEngine
the TestEngine to use; must not be null
testEngine
,
LauncherDiscoveryRequest
the EngineDiscoveryResults to use; must not be null
discoveryRequest
)

Discover tests for the given LauncherDiscoveryRequest using the supplied TestEngine.

private static LauncherDiscoveryResult
public static EngineTestKit.Builder

Returns:

the engine execution Builder
engine
(String
the ID of the TestEngine to use; must not be null or blank
engineId
)

Create an execution Builder for the TestEngine with the supplied ID.

The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

public static EngineTestKit.Builder

Returns:

the engine execution Builder
engine
(TestEngine
the TestEngine to use; must not be null
testEngine
)

Create an execution Builder for the supplied TestEngine.

public static EngineExecutionResults

Returns:

the results of the execution
execute
(String
the ID of the TestEngine to use; must not be null or blank
engineId
,
LauncherDiscoveryRequest
the LauncherDiscoveryRequest to use
discoveryRequest
)

Execute tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.

The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

public static EngineExecutionResults

Returns:

the recorded EngineExecutionResults
execute
(TestEngine
the TestEngine to use; must not be null
testEngine
,
LauncherDiscoveryRequest
the LauncherDiscoveryRequest to use; must not be null
discoveryRequest
)

Execute tests for the given LauncherDiscoveryRequest using the supplied TestEngine.

private static void
private static TestEngine
private static NamespacedHierarchicalStore<Namespace>
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EngineTestKitback to summary
private EngineTestKit()

Method Detail

discoverback to summary
public static EngineDiscoveryResults discover(String engineId, LauncherDiscoveryRequest discoveryRequest)

Discover tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.

The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

Parameters
engineId:String

the ID of the TestEngine to use; must not be null or blank

discoveryRequest:LauncherDiscoveryRequest

the LauncherDiscoveryRequest to use

Returns:EngineDiscoveryResults

the results of the discovery

Annotations
@API
status:EXPERIMENTAL
since:6.0
Exceptions
PreconditionViolationException:
for invalid arguments or if the TestEngine with the supplied ID cannot be loaded
Since
1.13
See Also
discover(TestEngine, LauncherDiscoveryRequest), engine(String), engine(TestEngine)
discoverback to summary
public static EngineDiscoveryResults discover(TestEngine testEngine, LauncherDiscoveryRequest discoveryRequest)

Discover tests for the given LauncherDiscoveryRequest using the supplied TestEngine.

org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

Parameters
testEngine:TestEngine

the TestEngine to use; must not be null

discoveryRequest:LauncherDiscoveryRequest

the EngineDiscoveryResults to use; must not be null

Returns:EngineDiscoveryResults

the recorded EngineExecutionResults

Annotations
@API
status:EXPERIMENTAL
since:6.0
Exceptions
PreconditionViolationException:
for invalid arguments
Since
1.13
See Also
discover(String, LauncherDiscoveryRequest), engine(String), engine(TestEngine)
discoverUsingOrchestratorback to summary
private static LauncherDiscoveryResult discoverUsingOrchestrator(TestEngine testEngine, LauncherDiscoveryRequest discoveryRequest)
engineback to summary
public static EngineTestKit.Builder engine(String engineId)

Create an execution Builder for the TestEngine with the supplied ID.

The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

Example Usage

EngineTestKit
    .engine("junit-jupiter")
    .selectors(selectClass(MyTests.class))
    .execute()
    .testEvents()
    .assertStatistics(stats -> stats.started(2).finished(2));
Parameters
engineId:String

the ID of the TestEngine to use; must not be null or blank

Returns:EngineTestKit.Builder

the engine execution Builder

Exceptions
PreconditionViolationException:
if the supplied ID is null or blank, or if the TestEngine with the supplied ID cannot be loaded
See Also
engine(TestEngine), execute(String, LauncherDiscoveryRequest), execute(TestEngine, LauncherDiscoveryRequest)
engineback to summary
public static EngineTestKit.Builder engine(TestEngine testEngine)

Create an execution Builder for the supplied TestEngine.

Example Usage

EngineTestKit
    .engine(new MyTestEngine())
    .selectors(selectClass(MyTests.class))
    .execute()
    .testEvents()
    .assertStatistics(stats -> stats.started(2).finished(2));
Parameters
testEngine:TestEngine

the TestEngine to use; must not be null

Returns:EngineTestKit.Builder

the engine execution Builder

Exceptions
PreconditionViolationException:
if the TestEngine is null
See Also
engine(String), execute(String, LauncherDiscoveryRequest), execute(TestEngine, LauncherDiscoveryRequest)
executeback to summary
public static EngineExecutionResults execute(String engineId, LauncherDiscoveryRequest discoveryRequest)

Execute tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.

The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

Parameters
engineId:String

the ID of the TestEngine to use; must not be null or blank

discoveryRequest:LauncherDiscoveryRequest

the LauncherDiscoveryRequest to use

Returns:EngineExecutionResults

the results of the execution

Exceptions
PreconditionViolationException:
for invalid arguments or if the TestEngine with the supplied ID cannot be loaded
Since
1.7
See Also
execute(TestEngine, LauncherDiscoveryRequest), engine(String), engine(TestEngine)
executeback to summary
public static EngineExecutionResults execute(TestEngine testEngine, LauncherDiscoveryRequest discoveryRequest)

Execute tests for the given LauncherDiscoveryRequest using the supplied TestEngine.

org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

Parameters
testEngine:TestEngine

the TestEngine to use; must not be null

discoveryRequest:LauncherDiscoveryRequest

the LauncherDiscoveryRequest to use; must not be null

Returns:EngineExecutionResults

the recorded EngineExecutionResults

Exceptions
PreconditionViolationException:
for invalid arguments
Since
1.7
See Also
execute(String, LauncherDiscoveryRequest), engine(String), engine(TestEngine)
executeUsingLauncherOrchestrationback to summary
private static void executeUsingLauncherOrchestration(TestEngine testEngine, LauncherDiscoveryRequest discoveryRequest, EngineExecutionListener listener, CancellationToken cancellationToken)
loadTestEngineback to summary
private static TestEngine loadTestEngine(String engineId)
Annotations
@SuppressWarnings:unchecked
newStoreback to summary
private static NamespacedHierarchicalStore<Namespace> newStore(@Nullable NamespacedHierarchicalStore<Namespace> parentStore)
withRequestLevelStoreback to summary
private static void withRequestLevelStore(Consumer<NamespacedHierarchicalStore<Namespace>> action)
org.junit.platform.testkit.engine back to summary

public final Class EngineTestKit.Builder

extends Object
Class Inheritance

TestEngine execution builder.

See EngineTestKit#engine(String) and EngineTestKit#engine(TestEngine) for example usage.

Since
1.4
See Also
selectors(DiscoverySelector...), filters(Filter...), configurationParameter(String, String), configurationParameters(Map), execute()

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private @Nullable CancellationToken
private final LauncherDiscoveryRequestBuilder
private final TestEngine

Constructor Summary

AccessConstructor and Description
private
Builder(TestEngine testEngine)

Method Summary

Modifier and TypeMethod and Description
public EngineTestKit.Builder

Returns:

this builder for method chaining
cancellationToken
(CancellationToken
the cancellation token to use; never null
cancellationToken
)

Set the CancellationToken to use for execution.

public EngineTestKit.Builder

Returns:

this builder for method chaining
configurationParameter
(String
the configuration parameter key under which to store the value; never null or blank
key
,
String
the value to store
value
)

Add the supplied configuration parameter.

public EngineTestKit.Builder

Returns:

this builder for method chaining
configurationParameters
(Map<String, String>
the map of configuration parameters to add; never null
configurationParameters
)

Add all of the supplied configuration parameters.

public EngineDiscoveryResults

Returns:

the recorded EngineDiscoveryResults
discover
()

Discover tests for the configured TestEngine, discovery selectors, discovery filters, and configuration parameters.

public EngineTestKit.Builder
enableImplicitConfigurationParameters(boolean enabled)

Configure whether implicit configuration parameters should be considered.

public EngineExecutionResults

Returns:

the recorded EngineExecutionResults
execute
()

Execute tests for the configured TestEngine, discovery selectors, discovery filters, and configuration parameters.

public EngineTestKit.Builder

Returns:

this builder for method chaining
filters
(Filter<?>...
the filters to add; never null
filters
)

Add all of the supplied filters.

public EngineTestKit.Builder

Returns:

this builder for method chaining
outputDirectoryCreator
(OutputDirectoryCreator
the output directory creator to use; never null
outputDirectoryCreator
)

Set the OutputDirectoryCreator to use.

public EngineTestKit.Builder

Returns:

this builder for method chaining
outputDirectoryProvider
(OutputDirectoryProvider
the output directory provider to use; never null
outputDirectoryProvider
)
Deprecated for removal since 1.14. Please use outputDirectoryCreator(OutputDirectoryCreator) instead

Set the org.junit.platform.engine.reporting.OutputDirectoryProvider to use.

public EngineTestKit.Builder

Returns:

this builder for method chaining
selectors
(DiscoverySelector...
the discovery selectors to add; never null
selectors
)

Add all of the supplied discovery selectors.

public EngineTestKit.Builder

Returns:

this builder for method chaining
selectors
(List<? extends DiscoverySelector>
the discovery selectors to add; never null
selectors
)

Add all of the supplied discovery selectors.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cancellationTokenback to summary
private @Nullable CancellationToken cancellationToken
requestBuilderback to summary
private final LauncherDiscoveryRequestBuilder requestBuilder
testEngineback to summary
private final TestEngine testEngine

Constructor Detail

Builderback to summary
private Builder(TestEngine testEngine)

Method Detail

cancellationTokenback to summary
public EngineTestKit.Builder cancellationToken(CancellationToken cancellationToken)

Set the CancellationToken to use for execution.

Parameters
cancellationToken:CancellationToken

the cancellation token to use; never null

Returns:EngineTestKit.Builder

this builder for method chaining

Annotations
@API
status:EXPERIMENTAL
since:6.0
Since
6.0
See Also
CancellationToken
configurationParameterback to summary
public EngineTestKit.Builder configurationParameter(String key, String value)

Add the supplied configuration parameter.

Parameters
key:String

the configuration parameter key under which to store the value; never null or blank

value:String

the value to store

Returns:EngineTestKit.Builder

this builder for method chaining

See Also
selectors(DiscoverySelector...), filters(Filter...), configurationParameters(Map), execute(), org.junit.platform.engine.ConfigurationParameters
configurationParametersback to summary
public EngineTestKit.Builder configurationParameters(Map<String, String> configurationParameters)

Add all of the supplied configuration parameters.

Parameters
configurationParameters:Map<String, String>

the map of configuration parameters to add; never null

Returns:EngineTestKit.Builder

this builder for method chaining

See Also
selectors(DiscoverySelector...), filters(Filter...), configurationParameter(String, String), execute(), org.junit.platform.engine.ConfigurationParameters
discoverback to summary
public EngineDiscoveryResults discover()

Discover tests for the configured TestEngine, discovery selectors, discovery filters, and configuration parameters.

Returns:EngineDiscoveryResults

the recorded EngineDiscoveryResults

Annotations
@API
status:EXPERIMENTAL
since:6.0
Since
1.13
See Also
selectors(DiscoverySelector...), filters(Filter...), configurationParameter(String, String), configurationParameters(Map)
enableImplicitConfigurationParametersback to summary
public EngineTestKit.Builder enableImplicitConfigurationParameters(boolean enabled)

Configure whether implicit configuration parameters should be considered.

By default, only configuration parameters that are passed explicitly to this builder are taken into account. Passing true to this method, enables additionally reading configuration parameters from implicit sources, i.e. system properties and the junit-platform.properties classpath resource.

Annotations
@API
status:STABLE
since:1.10
See Also
configurationParameter(String, String), configurationParameters(Map)
executeback to summary
public EngineExecutionResults execute()

Execute tests for the configured TestEngine, discovery selectors, discovery filters, and configuration parameters.

Returns:EngineExecutionResults

the recorded EngineExecutionResults

See Also
selectors(DiscoverySelector...), filters(Filter...), configurationParameter(String, String), configurationParameters(Map)
filtersback to summary
public EngineTestKit.Builder filters(Filter<?>... filters)

Add all of the supplied filters.

Built-in discovery filters can be created via the static factory methods in org.junit.platform.engine.discovery.ClassNameFilter and org.junit.platform.engine.discovery.PackageNameFilter.

Built-in post-discovery filters can be created via the static factory methods in org.junit.platform.launcher.TagFilter.

Parameters
filters:Filter<?>[]

the filters to add; never null

Returns:EngineTestKit.Builder

this builder for method chaining

Annotations
@API
status:STABLE
since:1.10
Since
1.7
See Also
selectors(DiscoverySelector...), configurationParameter(String, String), configurationParameters(Map), execute()
outputDirectoryCreatorback to summary
public EngineTestKit.Builder outputDirectoryCreator(OutputDirectoryCreator outputDirectoryCreator)

Set the OutputDirectoryCreator to use.

If not specified, a default implementation will be used that throws an exception when attempting to create output directories. This is done to avoid accidentally writing output files to the file system.

Parameters
outputDirectoryCreator:OutputDirectoryCreator

the output directory creator to use; never null

Returns:EngineTestKit.Builder

this builder for method chaining

Annotations
@API
status:MAINTAINED
since:1.14
Since
1.12
See Also
OutputDirectoryCreator
outputDirectoryProviderback to summary
public EngineTestKit.Builder outputDirectoryProvider(OutputDirectoryProvider outputDirectoryProvider)

Deprecated

for removal since 1.14.

Please use outputDirectoryCreator(OutputDirectoryCreator) instead

Set the org.junit.platform.engine.reporting.OutputDirectoryProvider to use.

If not specified, a default provider will be used that throws an exception when attempting to create output directories. This is done to avoid accidentally writing output files to the file system.

Parameters
outputDirectoryProvider:OutputDirectoryProvider

the output directory provider to use; never null

Returns:EngineTestKit.Builder

this builder for method chaining

Annotations
@SuppressWarnings:removal
@Deprecated
since:1.14
forRemoval:true
@API
status:DEPRECATED
since:1.14
Since
1.12
See Also
org.junit.platform.engine.reporting.OutputDirectoryProvider
selectorsback to summary
public EngineTestKit.Builder selectors(DiscoverySelector... selectors)

Add all of the supplied discovery selectors.

Built-in discovery selectors can be created via the static factory methods in org.junit.platform.engine.discovery.DiscoverySelectors.

Parameters
selectors:DiscoverySelector[]

the discovery selectors to add; never null

Returns:EngineTestKit.Builder

this builder for method chaining

See Also
selectors(List), filters(Filter...), configurationParameter(String, String), configurationParameters(Map), execute()
selectorsback to summary
public EngineTestKit.Builder selectors(List<? extends DiscoverySelector> selectors)

Add all of the supplied discovery selectors.

Built-in discovery selectors can be created via the static factory methods in org.junit.platform.engine.discovery.DiscoverySelectors.

Parameters
selectors:List<? extends DiscoverySelector>

the discovery selectors to add; never null

Returns:EngineTestKit.Builder

this builder for method chaining

Annotations
@API
status:MAINTAINED
since:6.0
Since
6.0
See Also
selectors(DiscoverySelector...), filters(Filter...), configurationParameter(String, String), configurationParameters(Map), execute()
org.junit.platform.testkit.engine back to summary

private Class EngineTestKit.Builder.DisabledOutputDirectoryCreator

extends Object
implements OutputDirectoryCreator
Class Inheritance
  • java.lang.Object
  • org.junit.platform.testkit.engine.EngineTestKit.Builder.DisabledOutputDirectoryCreator
All Implemented Interfaces
org.junit.platform.engine.OutputDirectoryCreator

Field Summary

Modifier and TypeField and Description
private static final String
private static final OutputDirectoryCreator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Path
createOutputDirectory(TestDescriptor testDescriptor)

Implements org.junit.platform.engine.OutputDirectoryCreator.createOutputDirectory.

Create an output directory for the supplied test descriptor.

public Path
getRootDirectory()

Implements org.junit.platform.engine.OutputDirectoryCreator.getRootDirectory.

Returns the root directory for all output files; never null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FAILURE_MESSAGEback to summary
private static final String FAILURE_MESSAGE
INSTANCEback to summary
private static final OutputDirectoryCreator INSTANCE

Constructor Detail

DisabledOutputDirectoryCreatorback to summary
private DisabledOutputDirectoryCreator()

Method Detail

createOutputDirectoryback to summary
public Path createOutputDirectory(TestDescriptor testDescriptor)

Implements org.junit.platform.engine.OutputDirectoryCreator.createOutputDirectory.

Doc from org.junit.platform.engine.OutputDirectoryCreator.createOutputDirectory.

Create an output directory for the supplied test descriptor.

Annotations
@Override
getRootDirectoryback to summary
public Path getRootDirectory()

Implements org.junit.platform.engine.OutputDirectoryCreator.getRootDirectory.

Doc from org.junit.platform.engine.OutputDirectoryCreator.getRootDirectory.

Returns the root directory for all output files; never null.

Annotations
@Override