Top Description Fields Constructors Methods
org.junit.platform.launcher.core

public final Class LauncherDiscoveryRequestBuilder

extends Object
Class Inheritance
Annotations
@API
status:STABLE
since:1.0
Static Imports
org.apiguardian.api.API.Status.DEPRECATED, .API.Status.EXPERIMENTAL, .API.Status.MAINTAINED, .API.Status.STABLE, org.junit.platform.launcher.LauncherConstants.OUTPUT_DIR_PROPERTY_NAME

The LauncherDiscoveryRequestBuilder provides a light-weight DSL for generating a LauncherDiscoveryRequest.

Example

import static org.junit.platform.engine.discovery.DiscoverySelectors.*;
import static org.junit.platform.engine.discovery.ClassNameFilter.*;
import static org.junit.platform.launcher.EngineFilter.*;
import static org.junit.platform.launcher.TagFilter.*;
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.discoveryRequest;

// ...

LauncherDiscoveryRequest discoveryRequest = discoveryRequest()
   .selectors(
       selectPackage("org.example.user"),
       selectClass("org.example.payment.PaymentTests"),
       selectClass(ShippingTests.class),
       selectMethod("org.example.order.OrderTests#test1"),
       selectMethod("org.example.order.OrderTests#test2()"),
       selectMethod("org.example.order.OrderTests#test3(java.lang.String)"),
       selectMethod("org.example.order.OrderTests", "test4"),
       selectMethod(OrderTests.class, "test5"),
       selectMethod(OrderTests.class, testMethod),
       selectUniqueId("unique-id-1"),
       selectUniqueId("unique-id-2")
   )
   .selectors(
       selectClasspathRoots(Set.of(Paths.get("/my/local/path1")))
   )
  .filters(
       includeEngines("junit-jupiter", "spek"),
       // excludeEngines("junit-vintage"),
       includeTags("fast"),
       // excludeTags("slow"),
       includeClassNamePatterns(".*Test[s]?")
       // includeClassNamePatterns("org\.example\.tests.*")
   )
   .configurationParameter("key1", "value1")
   .configurationParameters(configParameterMap)
   .build();
Since
1.0
See Also
org.junit.platform.engine.discovery.DiscoverySelectors, org.junit.platform.engine.discovery.ClassNameFilter, org.junit.platform.launcher.EngineFilter, org.junit.platform.launcher.TagFilter, LauncherExecutionRequestBuilder

Field Summary

Modifier and TypeField and Description
private final Map<String, String>
private final List<String>
public static final String
DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME

Property name used to set the default discovery listener that is added to all : Supported Values

Supported values are "logging" and "abortOnFailure".

private static final String
private final List<DiscoveryFilter<?>>
private final List<LauncherDiscoveryListener>
private final List<EngineFilter>
private boolean
private @Nullable OutputDirectoryCreator
private @Nullable ConfigurationParameters
private final List<PostDiscoveryFilter>
private final List<DiscoverySelector>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public LauncherDiscoveryRequest
build()

Build the LauncherDiscoveryRequest that has been configured via this builder.

private LauncherConfigurationParameters
public LauncherDiscoveryRequestBuilder

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 to the request.

public LauncherDiscoveryRequestBuilder

Returns:

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

Add all supplied configuration parameters to the request.

public LauncherDiscoveryRequestBuilder

Returns:

this builder for method chaining
configurationParametersResources
(String...
the classpath locations of the properties files never null
paths
)

Add all of the supplied configuration parameters resource files to the request.

public static LauncherDiscoveryRequestBuilder

Returns:

a new builder
discoveryRequest
()

Create a new LauncherDiscoveryRequestBuilder.

public LauncherDiscoveryRequestBuilder

Returns:

this builder for method chaining
enableImplicitConfigurationParameters
(boolean
true if implicit configuration parameters should be considered
enabled
)

Configure whether implicit configuration parameters should be considered.

public LauncherDiscoveryRequestBuilder

Returns:

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

Add all supplied filters to the request.

public LauncherExecutionRequestBuilder
forExecution()

Builds this discovery request and returns a new builder for creating a org.junit.platform.launcher.LauncherExecutionRequest that is initialized to contain the resulting discovery request.

private LauncherDiscoveryListener
private LauncherDiscoveryListener
private OutputDirectoryCreator
public LauncherDiscoveryRequestBuilder

Returns:

this builder for method chaining
listeners
(LauncherDiscoveryListener...
the LauncherDiscoveryListeners to add; never null
listeners
)

Add all supplied discovery listeners to the request.

public LauncherDiscoveryRequestBuilder

Returns:

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

Set the OutputDirectoryCreator to use for the request.

public LauncherDiscoveryRequestBuilder

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 for the request.

public LauncherDiscoveryRequestBuilder

Returns:

this builder for method chaining
parentConfigurationParameters
(ConfigurationParameters
the parent instance to use for looking up configuration parameters that have not been explicitly configured; never null
parentConfigurationParameters
)

Set the parent configuration parameters to use for the request.

public static LauncherDiscoveryRequestBuilder

Returns:

a new builder
request
()

Create a new LauncherDiscoveryRequestBuilder.

public LauncherDiscoveryRequestBuilder

Returns:

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

Add all supplied selectors to the request.

public LauncherDiscoveryRequestBuilder

Returns:

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

Add all supplied selectors to the request.

private void
storeFilter(Filter<?> filter)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configurationParametersback to summary
private final Map<String, String> configurationParameters
configurationParametersResourcesback to summary
private final List<String> configurationParametersResources
DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAMEback to summary
public static final String DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME

Property name used to set the default discovery listener that is added to all :

Supported Values

Supported values are "logging" and "abortOnFailure".

If not specified, the default is abortOnFailure.

DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_VALUEback to summary
private static final String DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_VALUE
discoveryFiltersback to summary
private final List<DiscoveryFilter<?>> discoveryFilters
discoveryListenersback to summary
private final List<LauncherDiscoveryListener> discoveryListeners
engineFiltersback to summary
private final List<EngineFilter> engineFilters
implicitConfigurationParametersEnabledback to summary
private boolean implicitConfigurationParametersEnabled
outputDirectoryCreatorback to summary
private @Nullable OutputDirectoryCreator outputDirectoryCreator
parentConfigurationParametersback to summary
private @Nullable ConfigurationParameters parentConfigurationParameters
postDiscoveryFiltersback to summary
private final List<PostDiscoveryFilter> postDiscoveryFilters
selectorsback to summary
private final List<DiscoverySelector> selectors

Constructor Detail

LauncherDiscoveryRequestBuilderback to summary
private LauncherDiscoveryRequestBuilder()

Method Detail

buildback to summary
public LauncherDiscoveryRequest build()

Build the LauncherDiscoveryRequest that has been configured via this builder.

buildLauncherConfigurationParametersback to summary
private LauncherConfigurationParameters buildLauncherConfigurationParameters()
configurationParameterback to summary
public LauncherDiscoveryRequestBuilder configurationParameter(String key, String value)

Add the supplied configuration parameter to the request.

Parameters
key:String

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

value:String

the value to store

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

configurationParametersback to summary
public LauncherDiscoveryRequestBuilder configurationParameters(Map<String, String> configurationParameters)

Add all supplied configuration parameters to the request.

Parameters
configurationParameters:Map<String, String>

the map of configuration parameters to add; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

See Also
configurationParameter(String, String)
configurationParametersResourcesback to summary
public LauncherDiscoveryRequestBuilder configurationParametersResources(String... paths)

Add all of the supplied configuration parameters resource files to the request.

Parameters
paths:String[]

the classpath locations of the properties files never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

discoveryRequestback to summary
public static LauncherDiscoveryRequestBuilder discoveryRequest()

Create a new LauncherDiscoveryRequestBuilder.

This method is an alias for request() and is intended to be used when statically imported — for example, via: import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.discoveryRequest;

Returns:LauncherDiscoveryRequestBuilder

a new builder

Annotations
@API
status:STABLE
since:6.0
Since
6.0
See Also
request()
enableImplicitConfigurationParametersback to summary
public LauncherDiscoveryRequestBuilder enableImplicitConfigurationParameters(boolean enabled)

Configure whether implicit configuration parameters should be considered.

By default, in addition to those parameters that are passed explicitly to this builder, configuration parameters are read from system properties and from the junit-platform.properties classpath resource. Passing false to this method, disables the latter two sources so that only explicit configuration parameters are taken into account.

Parameters
enabled:boolean

true if implicit configuration parameters should be considered

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

Annotations
@API
status:STABLE
since:1.10
Since
1.7
See Also
configurationParameter(String, String), configurationParameters(Map)
filtersback to summary
public LauncherDiscoveryRequestBuilder filters(Filter<?>... filters)

Add all supplied filters to the request.

The filters are combined using AND semantics, i.e. all of them have to include a resource for it to end up in the test plan.

Warning

be cautious when registering multiple competing include EngineFilters or multiple competing exclude EngineFilters for the same discovery request since doing so will likely lead to undesirable results (i.e., zero engines being active).

Parameters
filters:Filter<?>[]

the Filters to add; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

forExecutionback to summary
public LauncherExecutionRequestBuilder forExecution()

Builds this discovery request and returns a new builder for creating a org.junit.platform.launcher.LauncherExecutionRequest that is initialized to contain the resulting discovery request.

Returns:LauncherExecutionRequestBuilder

a new LauncherExecutionRequestBuilder

Annotations
@API
status:EXPERIMENTAL
since:6.0
Since
6.0
getDefaultLauncherDiscoveryListenerback to summary
private LauncherDiscoveryListener getDefaultLauncherDiscoveryListener(ConfigurationParameters configurationParameters)
getLauncherDiscoveryListenerback to summary
private LauncherDiscoveryListener getLauncherDiscoveryListener(ConfigurationParameters configurationParameters)
getOutputDirectoryCreatorback to summary
private OutputDirectoryCreator getOutputDirectoryCreator(LauncherConfigurationParameters configurationParameters)
listenersback to summary
public LauncherDiscoveryRequestBuilder listeners(LauncherDiscoveryListener... listeners)

Add all supplied discovery listeners to the request.

In addition to the listeners registered using this method, this builder will add a default listener to this request that can be specified using the junit.platform.discovery.listener.default configuration parameter.

Parameters
listeners:LauncherDiscoveryListener[]

the LauncherDiscoveryListeners to add; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

Annotations
@API
status:STABLE
since:1.10
Since
1.6
See Also
LauncherDiscoveryListener, LauncherDiscoveryListeners, LauncherDiscoveryRequestBuilder#DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME
outputDirectoryCreatorback to summary
public LauncherDiscoveryRequestBuilder outputDirectoryCreator(OutputDirectoryCreator outputDirectoryCreator)

Set the OutputDirectoryCreator to use for the request.

If not specified, a default implementation will be used that can be configured via the junit.platform.reporting.output.dir configuration parameter.

Parameters
outputDirectoryCreator:OutputDirectoryCreator

the output directory creator to use; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

Annotations
@SuppressWarnings:removal
@API
status:MAINTAINED
since:1.14
Since
1.14
See Also
OutputDirectoryCreator, LauncherConstants#OUTPUT_DIR_PROPERTY_NAME
outputDirectoryProviderback to summary
public LauncherDiscoveryRequestBuilder outputDirectoryProvider(OutputDirectoryProvider outputDirectoryProvider)

Deprecated

for removal since 1.14.

Please use outputDirectoryCreator(OutputDirectoryCreator) instead

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

If not specified, a default provider will be used that can be configured via the junit.platform.reporting.output.dir configuration parameter.

Parameters
outputDirectoryProvider:OutputDirectoryProvider

the output directory provider to use; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

Annotations
@SuppressWarnings:removal
@API
status:DEPRECATED
since:1.14
@Deprecated
since:1.14
forRemoval:true
Since
1.12
See Also
org.junit.platform.engine.reporting.OutputDirectoryProvider, LauncherConstants#OUTPUT_DIR_PROPERTY_NAME
parentConfigurationParametersback to summary
public LauncherDiscoveryRequestBuilder parentConfigurationParameters(ConfigurationParameters parentConfigurationParameters)

Set the parent configuration parameters to use for the request.

Any explicit configuration parameters configured via configurationParameter(String, String) or configurationParameters(Map) takes precedence over the supplied configuration parameters.

Parameters
parentConfigurationParameters:ConfigurationParameters

the parent instance to use for looking up configuration parameters that have not been explicitly configured; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

Annotations
@API
status:STABLE
since:1.10
Since
1.8
See Also
configurationParameter(String, String), configurationParameters(Map)
requestback to summary
public static LauncherDiscoveryRequestBuilder request()

Create a new LauncherDiscoveryRequestBuilder.

Returns:LauncherDiscoveryRequestBuilder

a new builder

See Also
discoveryRequest()
selectorsback to summary
public LauncherDiscoveryRequestBuilder selectors(DiscoverySelector... selectors)

Add all supplied selectors to the request.

Parameters
selectors:DiscoverySelector[]

the DiscoverySelectors to add; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

selectorsback to summary
public LauncherDiscoveryRequestBuilder selectors(List<? extends DiscoverySelector> selectors)

Add all supplied selectors to the request.

Parameters
selectors:List<? extends DiscoverySelector>

the DiscoverySelectors to add; never null

Returns:LauncherDiscoveryRequestBuilder

this builder for method chaining

storeFilterback to summary
private void storeFilter(Filter<?> filter)