Class 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:
    DiscoverySelectors, ClassNameFilter, EngineFilter, TagFilter
    • Constructor Detail

      • LauncherDiscoveryRequestBuilder

        public LauncherDiscoveryRequestBuilder()
    • Method Detail

      • selectors

        public LauncherDiscoveryRequestBuilder selectors​(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 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​(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