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 executing a test plan for a given TestEngine and then accessing the results via a fluent API to verify the expected results.
Since:
1.4
See Also:
engine(String), engine(TestEngine), execute(String, LauncherDiscoveryRequest), execute(TestEngine, LauncherDiscoveryRequest), EngineExecutionResults
  • 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(TestEngine), execute(String, LauncherDiscoveryRequest), execute(TestEngine, LauncherDiscoveryRequest)
    • 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:
      engine(String), execute(String, LauncherDiscoveryRequest), execute(TestEngine, LauncherDiscoveryRequest)
    • 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(String, LauncherDiscoveryRequest), engine(String), engine(TestEngine)
    • 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(TestEngine, LauncherDiscoveryRequest), engine(String), engine(TestEngine)
    • 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(TestEngine, LauncherDiscoveryRequest), engine(String), engine(TestEngine)
    • 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:
      execute(String, LauncherDiscoveryRequest), engine(String), engine(TestEngine)