Class EngineTestKit

java.lang.Object
org.junit.platform.testkit.engine.EngineTestKit

@API(status=MAINTAINED, since="1.7") public final class EngineTestKit extends Object
EngineTestKit provides support for discovering and executing tests for a given TestEngine and provides convenient access to the results.

For discovery, EngineDiscoveryResults provides access to the TestDescriptor of the engine and any DiscoveryIssues that were encountered.

For execution, EngineExecutionResults provides a fluent API to verify the expected results.

Since:
1.4
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    TestEngine execution builder.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    discover(String engineId, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
    Discover tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.
    discover(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
    Discover tests for the given LauncherDiscoveryRequest using the supplied TestEngine.
    private static org.junit.platform.launcher.core.LauncherDiscoveryResult
    discoverUsingOrchestrator(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
     
    engine(String engineId)
    Create an execution EngineTestKit.Builder for the TestEngine with the supplied ID.
    engine(org.junit.platform.engine.TestEngine testEngine)
    Create an execution EngineTestKit.Builder for the supplied TestEngine.
    execute(String engineId, org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest)
    Deprecated.
    execute(String engineId, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
    Execute tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.
    execute(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest)
    Deprecated.
    execute(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
    Execute tests for the given LauncherDiscoveryRequest using the supplied TestEngine.
    private static void
    executeDirectly(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, org.junit.platform.engine.EngineExecutionListener listener)
     
    private static void
    executeUsingLauncherOrchestration(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest, org.junit.platform.engine.EngineExecutionListener listener)
     
    private static org.junit.platform.engine.TestEngine
     
    private static org.junit.platform.engine.support.store.NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace>
    newStore(org.junit.platform.engine.support.store.NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace> parentStore)
     
    private static void
    withRequestLevelStore(Consumer<org.junit.platform.engine.support.store.NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace>> action)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EngineTestKit

      private EngineTestKit()
  • Method Details

    • engine

      public static EngineTestKit.Builder engine(String engineId)
      Create an execution EngineTestKit.Builder for the TestEngine with the supplied ID.

      The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

      Example Usage

      EngineTestKit
          .engine("junit-jupiter")
          .selectors(selectClass(MyTests.class))
          .execute()
          .testEvents()
          .assertStatistics(stats -> stats.started(2).finished(2));
      
      Parameters:
      engineId - the ID of the TestEngine to use; must not be null or blank
      Returns:
      the engine execution Builder
      Throws:
      org.junit.platform.commons.PreconditionViolationException - if the supplied ID is null or blank, or if the TestEngine with the supplied ID cannot be loaded
      See Also:
    • engine

      public static EngineTestKit.Builder engine(org.junit.platform.engine.TestEngine testEngine)
      Create an execution EngineTestKit.Builder for the supplied TestEngine.

      Example Usage

      EngineTestKit
          .engine(new MyTestEngine())
          .selectors(selectClass(MyTests.class))
          .execute()
          .testEvents()
          .assertStatistics(stats -> stats.started(2).finished(2));
      
      Parameters:
      testEngine - the TestEngine to use; must not be null
      Returns:
      the engine execution Builder
      Throws:
      org.junit.platform.commons.PreconditionViolationException - if the TestEngine is null
      See Also:
    • discover

      @API(status=MAINTAINED, since="1.13.3") public static EngineDiscoveryResults discover(String engineId, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
      Discover tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.

      The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

      LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

      Parameters:
      engineId - the ID of the TestEngine to use; must not be null or blank
      discoveryRequest - the LauncherDiscoveryRequest to use
      Returns:
      the results of the discovery
      Throws:
      org.junit.platform.commons.PreconditionViolationException - for invalid arguments or if the TestEngine with the supplied ID cannot be loaded
      Since:
      1.13
      See Also:
    • discover

      @API(status=MAINTAINED, since="1.13.3") public static EngineDiscoveryResults discover(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
      Discover tests for the given LauncherDiscoveryRequest using the supplied TestEngine.

      LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

      Parameters:
      testEngine - the TestEngine to use; must not be null
      discoveryRequest - the EngineDiscoveryResults to use; must not be null
      Returns:
      the recorded EngineExecutionResults
      Throws:
      org.junit.platform.commons.PreconditionViolationException - for invalid arguments
      Since:
      1.13
      See Also:
    • execute

      @Deprecated @API(status=DEPRECATED, since="1.7") public static EngineExecutionResults execute(String engineId, org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest)
      Deprecated.
      Execute tests for the given EngineDiscoveryRequest using the TestEngine with the supplied ID.

      The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

      Note that LauncherDiscoveryRequest from the junit-platform-launcher module is a subtype of EngineDiscoveryRequest. It is therefore quite convenient to make use of the DSL provided in LauncherDiscoveryRequestBuilder to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(String) for a more fluent API.

      Parameters:
      engineId - the ID of the TestEngine to use; must not be null or blank
      discoveryRequest - the EngineDiscoveryRequest to use
      Returns:
      the results of the execution
      Throws:
      org.junit.platform.commons.PreconditionViolationException - for invalid arguments or if the TestEngine with the supplied ID cannot be loaded
      See Also:
    • execute

      public static EngineExecutionResults execute(String engineId, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
      Execute tests for the given LauncherDiscoveryRequest using the TestEngine with the supplied ID.

      The TestEngine will be loaded via Java's ServiceLoader mechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.

      LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

      Parameters:
      engineId - the ID of the TestEngine to use; must not be null or blank
      discoveryRequest - the LauncherDiscoveryRequest to use
      Returns:
      the results of the execution
      Throws:
      org.junit.platform.commons.PreconditionViolationException - for invalid arguments or if the TestEngine with the supplied ID cannot be loaded
      Since:
      1.7
      See Also:
    • execute

      @Deprecated @API(status=DEPRECATED, since="1.7") public static EngineExecutionResults execute(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest)
      Deprecated.
      Execute tests for the given EngineDiscoveryRequest using the supplied TestEngine.

      Note that LauncherDiscoveryRequest from the junit-platform-launcher module is a subtype of EngineDiscoveryRequest. It is therefore quite convenient to make use of the DSL provided in LauncherDiscoveryRequestBuilder to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

      Parameters:
      testEngine - the TestEngine to use; must not be null
      discoveryRequest - the EngineDiscoveryRequest to use; must not be null
      Returns:
      the recorded EngineExecutionResults
      Throws:
      org.junit.platform.commons.PreconditionViolationException - for invalid arguments
      See Also:
    • execute

      public static EngineExecutionResults execute(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
      Execute tests for the given LauncherDiscoveryRequest using the supplied TestEngine.

      LauncherDiscoveryRequestBuilder provides a convenient way to build an appropriate discovery request to supply to this method. As an alternative, consider using engine(TestEngine) for a more fluent API.

      Parameters:
      testEngine - the TestEngine to use; must not be null
      discoveryRequest - the LauncherDiscoveryRequest to use; must not be null
      Returns:
      the recorded EngineExecutionResults
      Throws:
      org.junit.platform.commons.PreconditionViolationException - for invalid arguments
      Since:
      1.7
      See Also:
    • executeDirectly

      private static void executeDirectly(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, org.junit.platform.engine.EngineExecutionListener listener)
    • executeUsingLauncherOrchestration

      private static void executeUsingLauncherOrchestration(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest, org.junit.platform.engine.EngineExecutionListener listener)
    • withRequestLevelStore

      private static void withRequestLevelStore(Consumer<org.junit.platform.engine.support.store.NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace>> action)
    • newStore

      private static org.junit.platform.engine.support.store.NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace> newStore(org.junit.platform.engine.support.store.NamespacedHierarchicalStore<org.junit.platform.engine.support.store.Namespace> parentStore)
    • discoverUsingOrchestrator

      private static org.junit.platform.launcher.core.LauncherDiscoveryResult discoverUsingOrchestrator(org.junit.platform.engine.TestEngine testEngine, org.junit.platform.launcher.LauncherDiscoveryRequest discoveryRequest)
    • loadTestEngine

      private static org.junit.platform.engine.TestEngine loadTestEngine(String engineId)