Class LauncherDiscoveryRequestBuilder


  • @API(status=STABLE,
         since="1.0")
    public final class LauncherDiscoveryRequestBuilder
    extends java.lang.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(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:
    DiscoverySelectors, ClassNameFilter, EngineFilter, TagFilter
    • Field Detail

      • DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME

        public static final java.lang.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:
        Constant Field Values
    • Constructor Detail

      • LauncherDiscoveryRequestBuilder

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

      • selectors

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

        public LauncherDiscoveryRequestBuilder selectors​(java.util.List<? extends org.junit.platform.engine.DiscoverySelector> selectors)
        Add all 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 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​(java.lang.String key,
                                                                      java.lang.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​(java.util.Map<java.lang.String,​java.lang.String> configurationParameters)
        Add all 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:
        configurationParameter(String, String)
      • configurationParametersResources

        public LauncherDiscoveryRequestBuilder configurationParametersResources​(java.lang.String... paths)
        Add all of the supplied configuration parameters resource files to the request.
        Parameters:
        paths - the classpath locations of the properties files never null
        Returns:
        this builder for method chaining
      • 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. Passing false 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:
        configurationParameter(String, String), configurationParameters(Map)
      • outputDirectoryCreator

        @API(status=MAINTAINED,
             since="1.14")
        public LauncherDiscoveryRequestBuilder outputDirectoryCreator​(org.junit.platform.engine.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 - the output directory creator to use; never null
        Returns:
        this builder for method chaining
        Since:
        1.14
        See Also:
        OutputDirectoryCreator, LauncherConstants.OUTPUT_DIR_PROPERTY_NAME