Class LauncherDiscoveryRequestBuilder

java.lang.Object
org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder

@API(status=STABLE, since="1.0") public final class LauncherDiscoveryRequestBuilder extends Object
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.*;

 // ...

   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(new File("/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 Details

    • DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME

      public static final String 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

      @API(status=DEPRECATED, since="1.8") @Deprecated public LauncherDiscoveryRequestBuilder()
      Deprecated.
  • Method Details

    • request

      public static LauncherDiscoveryRequestBuilder request()
      Create a new LauncherDiscoveryRequestBuilder.
      Returns:
      a new builder
    • selectors

      public LauncherDiscoveryRequestBuilder selectors(org.junit.platform.engine.DiscoverySelector... selectors)
      Add all of the supplied selectors to the request.
      Parameters:
      selectors - the DiscoverySelectors to add; never null
      Returns:
      this builder for method chaining
    • selectors

      public LauncherDiscoveryRequestBuilder selectors(List<? extends org.junit.platform.engine.DiscoverySelector> selectors)
      Add all of the supplied selectors to the request.
      Parameters:
      selectors - the DiscoverySelectors to add; never null
      Returns:
      this builder for method chaining
    • filters

      public LauncherDiscoveryRequestBuilder filters(org.junit.platform.engine.Filter<?>... filters)
      Add all of the 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 - the Filters to add; never null
      Returns:
      this builder for method chaining
    • configurationParameter

      public LauncherDiscoveryRequestBuilder configurationParameter(String key, String value)
      Add the supplied configuration parameter to the request.
      Parameters:
      key - the configuration parameter key under which to store the value; never null or blank
      value - the value to store
      Returns:
      this builder for method chaining
    • configurationParameters

      public LauncherDiscoveryRequestBuilder configurationParameters(Map<String,String> configurationParameters)
      Add all of the supplied configuration parameters to the request.
      Parameters:
      configurationParameters - the map of configuration parameters to add; never null
      Returns:
      this builder for method chaining
      See Also:
    • parentConfigurationParameters

      @API(status=EXPERIMENTAL, since="1.8") public LauncherDiscoveryRequestBuilder parentConfigurationParameters(org.junit.platform.engine.ConfigurationParameters configurationParameters)
      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:
      configurationParameters - the parent instance to be used for looking up configuration parameters that have not been explicitly configured; never null
      Since:
      1.8
      See Also:
    • listeners

      @API(status=EXPERIMENTAL, since="1.6") public LauncherDiscoveryRequestBuilder listeners(LauncherDiscoveryListener... listeners)
      Add all of the 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 - the LauncherDiscoveryListeners to add; never null
      Returns:
      this builder for method chaining
      Since:
      1.6
      See Also:
    • enableImplicitConfigurationParameters

      @API(status=EXPERIMENTAL, since="1.7") 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.

      Since:
      1.7
      See Also:
    • build

      public LauncherDiscoveryRequest build()
      Build the LauncherDiscoveryRequest that has been configured via this builder.