Class SuiteLauncherDiscoveryRequestBuilder

java.lang.Object
org.junit.platform.suite.commons.SuiteLauncherDiscoveryRequestBuilder

@API(status=INTERNAL, since="1.8", consumers={"org.junit.platform.suite.engine","org.junit.platform.runner"}) public final class SuiteLauncherDiscoveryRequestBuilder extends Object
The SuiteLauncherDiscoveryRequestBuilder provides a light-weight DSL for generating a LauncherDiscoveryRequest specifically tailored for suite execution.

Example


 SuiteLauncherDiscoveryRequestBuilder.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("key", "value")
   .enableImplicitConfigurationParameters(true)
   .applyConfigurationParametersFromSuite(MySuite.class)
   .applySelectorsAndFiltersFromSuite(MySuite.class)
   .build();
 
Since:
1.8
See Also:
  • DiscoverySelectors
  • ClassNameFilter
  • EngineFilter
  • TagFilter
  • Method Details

    • request

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

      public SuiteLauncherDiscoveryRequestBuilder 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 SuiteLauncherDiscoveryRequestBuilder selectors(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 SuiteLauncherDiscoveryRequestBuilder 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
    • filterStandardClassNamePatterns

      public SuiteLauncherDiscoveryRequestBuilder filterStandardClassNamePatterns(boolean filterStandardClassNamePatterns)
      Specify whether to filter standard class name patterns.

      If set to true, standard class name patterns are filtered.

      Parameters:
      filterStandardClassNamePatterns - true to filter standard class name patterns, false otherwise
      Returns:
      this builder for method chaining
    • configurationParameter

      public SuiteLauncherDiscoveryRequestBuilder 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 SuiteLauncherDiscoveryRequestBuilder configurationParameters(Map<String,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:
    • configurationParametersResource

      public SuiteLauncherDiscoveryRequestBuilder configurationParametersResource(String resourceFile)
    • parentConfigurationParameters

      public SuiteLauncherDiscoveryRequestBuilder parentConfigurationParameters(org.junit.platform.engine.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 - the parent instance to use for looking up configuration parameters that have not been explicitly configured; never null
      Returns:
      this builder for method chaining
      See Also:
    • enableImplicitConfigurationParameters

      public SuiteLauncherDiscoveryRequestBuilder 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
      See Also:
    • outputDirectoryCreator

      public SuiteLauncherDiscoveryRequestBuilder outputDirectoryCreator(org.junit.platform.engine.OutputDirectoryCreator outputDirectoryCreator)
    • listener

      @API(status=INTERNAL, since="1.13") public SuiteLauncherDiscoveryRequestBuilder listener(org.junit.platform.launcher.LauncherDiscoveryListener listener)
    • suite

      @Deprecated @API(status=DEPRECATED, since="1.11") public SuiteLauncherDiscoveryRequestBuilder suite(Class<?> suiteClass)
      Apply a suite's annotation-based configuration, selectors, and filters to this builder.
      Parameters:
      suiteClass - the class to apply the annotations from; never null
      Returns:
      this builder for method chaining
      See Also:
      • Suite
    • applyConfigurationParametersFromSuite

      public SuiteLauncherDiscoveryRequestBuilder applyConfigurationParametersFromSuite(Class<?> suiteClass)
      Apply a suite's annotation-based configuration to this builder.

      This will apply the configuration from the following annotations.

      • ConfigurationParameter
      • DisableParentConfigurationParameters
      Parameters:
      suiteClass - the class to apply the configuration annotations from; never null
      Returns:
      this builder for method chaining
      Since:
      1.11
      See Also:
      • Suite
    • applySelectorsAndFiltersFromSuite

      public SuiteLauncherDiscoveryRequestBuilder applySelectorsAndFiltersFromSuite(Class<?> suiteClass)
      Apply a suite's annotation-based discovery selectors and filters to this builder.

      This will apply the configuration from the following annotations.

      • ExcludeClassNamePatterns
      • ExcludeEngines
      • ExcludePackages
      • ExcludeTags
      • IncludeClassNamePatterns
      • IncludeEngines
      • IncludePackages
      • IncludeTags
      • SelectClasses
      • SelectClasspathResource
      • SelectDirectories
      • SelectFile
      • SelectMethod
      • SelectModules
      • SelectUris
      • SelectPackages
      • Select
      Parameters:
      suiteClass - the class to apply the discovery selectors and filter annotations from; never null
      Returns:
      this builder for method chaining
      Since:
      1.11
      See Also:
      • Suite
    • build

      public org.junit.platform.launcher.LauncherDiscoveryRequest build()
      Build the LauncherDiscoveryRequest that has been configured via this builder.