Class LauncherDiscoveryRequestBuilder
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.*; // ... LauncherDiscoveryRequestBuilder.request() .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), selectClasspathRoots(Collections.singleton(Paths.get("/my/local/path1"))), selectUniqueId("unique-id-1"), selectUniqueId("unique-id-2") ) .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:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Property name used to set the default discovery listener that is added to all : "junit.platform.discovery.listener.default" -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build theLauncherDiscoveryRequest
that has been configured via this builder.configurationParameter
(String key, String value) Add the supplied configuration parameter to the request.configurationParameters
(Map<String, String> configurationParameters) Add all supplied configuration parameters to the request.configurationParametersResources
(String... paths) Add all of the supplied configuration parameters resource files to the request.enableImplicitConfigurationParameters
(boolean enabled) Configure whether implicit configuration parameters should be considered.Add all suppliedfilters
to the request.listeners
(LauncherDiscoveryListener... listeners) Add all supplied discovery listeners to the request.parentConfigurationParameters
(ConfigurationParameters parentConfigurationParameters) Set the parent configuration parameters to use for the request.request()
Create a newLauncherDiscoveryRequestBuilder
.selectors
(List<? extends DiscoverySelector> selectors) Add all suppliedselectors
to the request.selectors
(DiscoverySelector... selectors) Add all suppliedselectors
to the request.
-
Field Details
-
DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME
Property name used to set the default discovery listener that is added to all : "junit.platform.discovery.listener.default"Supported Values
Supported values are
"logging"
and"abortOnFailure"
.If not specified, the default is "abortOnFailure".
- See Also:
-
-
Constructor Details
-
LauncherDiscoveryRequestBuilder
Deprecated.Userequest()
-
-
Method Details
-
request
Create a newLauncherDiscoveryRequestBuilder
.- Returns:
- a new builder
-
selectors
Add all suppliedselectors
to the request.- Parameters:
selectors
- theDiscoverySelectors
to add; nevernull
- Returns:
- this builder for method chaining
-
selectors
Add all suppliedselectors
to the request.- Parameters:
selectors
- theDiscoverySelectors
to add; nevernull
- Returns:
- this builder for method chaining
-
filters
Add all suppliedfilters
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 competingexclude
EngineFilters
for the same discovery request since doing so will likely lead to undesirable results (i.e., zero engines being active).- Parameters:
filters
- theFilter
s to add; nevernull
- Returns:
- this builder for method chaining
-
configurationParameter
Add the supplied configuration parameter to the request.- Parameters:
key
- the configuration parameter key under which to store the value; nevernull
or blankvalue
- the value to store- Returns:
- this builder for method chaining
-
configurationParameters
public LauncherDiscoveryRequestBuilder configurationParameters(Map<String, String> configurationParameters) Add all supplied configuration parameters to the request.- Parameters:
configurationParameters
- the map of configuration parameters to add; nevernull
- Returns:
- this builder for method chaining
- See Also:
-
configurationParametersResources
Add all of the supplied configuration parameters resource files to the request.- Parameters:
paths
- the classpath locations of the properties files nevernull
- Returns:
- this builder for method chaining
-
parentConfigurationParameters
@API(status=STABLE, since="1.10") public LauncherDiscoveryRequestBuilder parentConfigurationParameters(ConfigurationParameters parentConfigurationParameters) Set the parent configuration parameters to use for the request.Any explicit configuration parameters configured via
configurationParameter(String, String)
orconfigurationParameters(Map)
takes precedence over the supplied configuration parameters.- Parameters:
parentConfigurationParameters
- the parent instance to use for looking up configuration parameters that have not been explicitly configured; nevernull
- Returns:
- this builder for method chaining
- Since:
- 1.8
- See Also:
-
enableImplicitConfigurationParameters
@API(status=STABLE, since="1.10") 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. Passingfalse
to this method, disables the latter two sources so that only explicit configuration parameters are taken into account.- Parameters:
enabled
-true
if implicit configuration parameters should be considered- Returns:
- this builder for method chaining
- Since:
- 1.7
- See Also:
-
listeners
@API(status=STABLE, since="1.10") 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
- theLauncherDiscoveryListeners
to add; nevernull
- Returns:
- this builder for method chaining
- Since:
- 1.6
- See Also:
-
build
Build theLauncherDiscoveryRequest
that has been configured via this builder.
-
request()