Class EngineTestKit
- java.lang.Object
-
- org.junit.platform.testkit.engine.EngineTestKit
-
@API(status=EXPERIMENTAL, since="1.4") public final class EngineTestKit extends Object
EngineTestKitprovides support for executing a test plan for a givenTestEngineand then accessing the results via a fluent API to verify the expected results.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEngineTestKit.BuilderTestEngineexecution builder.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static EngineTestKit.Builderengine(String engineId)Create an executionEngineTestKit.Builderfor theTestEnginewith the supplied ID.static EngineTestKit.Builderengine(TestEngine testEngine)Create an executionEngineTestKit.Builderfor the suppliedTestEngine.static EngineExecutionResultsexecute(String engineId, EngineDiscoveryRequest discoveryRequest)Execute tests for the givenEngineDiscoveryRequestusing theTestEnginewith the supplied ID.static EngineExecutionResultsexecute(TestEngine testEngine, EngineDiscoveryRequest discoveryRequest)Execute tests for the givenEngineDiscoveryRequestusing the suppliedTestEngine.
-
-
-
Method Detail
-
engine
public static EngineTestKit.Builder engine(String engineId)
Create an executionEngineTestKit.Builderfor theTestEnginewith the supplied ID.The
TestEnginewill be loaded via Java'sServiceLoadermechanism, 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() .tests() .assertStatistics(stats -> stats.started(2).finished(2));- Parameters:
engineId- the ID of theTestEngineto use; must not benullor blank- Returns:
- the engine execution
Builder - Throws:
PreconditionViolationException- if the supplied ID isnullor blank, or if theTestEnginewith the supplied ID cannot be loaded- See Also:
engine(TestEngine),execute(String, EngineDiscoveryRequest),execute(TestEngine, EngineDiscoveryRequest)
-
engine
public static EngineTestKit.Builder engine(TestEngine testEngine)
Create an executionEngineTestKit.Builderfor the suppliedTestEngine.Example Usage
EngineTestKit .engine(new MyTestEngine()) .selectors(selectClass(MyTests.class)) .execute() .tests() .assertStatistics(stats -> stats.started(2).finished(2));- Parameters:
testEngine- theTestEngineto use; must not benull- Returns:
- the engine execution
Builder - Throws:
PreconditionViolationException- if theTestEngineisnull- See Also:
engine(String),execute(String, EngineDiscoveryRequest),execute(TestEngine, EngineDiscoveryRequest)
-
execute
public static EngineExecutionResults execute(String engineId, EngineDiscoveryRequest discoveryRequest)
Execute tests for the givenEngineDiscoveryRequestusing theTestEnginewith the supplied ID.The
TestEnginewill be loaded via Java'sServiceLoadermechanism, analogous to the manner in which test engines are loaded in the JUnit Platform Launcher API.Note that
LauncherDiscoveryRequestfrom thejunit-platform-launchermodule is a subtype ofEngineDiscoveryRequest. It is therefore quite convenient to make use of the DSL provided inLauncherDiscoveryRequestBuilderto build an appropriate discovery request to supply to this method. As an alternative, consider usingengine(String)for a more fluent API.- Parameters:
engineId- the ID of theTestEngineto use; must not benullor blankdiscoveryRequest- theEngineDiscoveryRequestto use- Returns:
- the results of the execution
- Throws:
PreconditionViolationException- for invalid arguments or if theTestEnginewith the supplied ID cannot be loaded- See Also:
execute(TestEngine, EngineDiscoveryRequest),engine(String),engine(TestEngine)
-
execute
public static EngineExecutionResults execute(TestEngine testEngine, EngineDiscoveryRequest discoveryRequest)
Execute tests for the givenEngineDiscoveryRequestusing the suppliedTestEngine.Note that
LauncherDiscoveryRequestfrom thejunit-platform-launchermodule is a subtype ofEngineDiscoveryRequest. It is therefore quite convenient to make use of the DSL provided inLauncherDiscoveryRequestBuilderto build an appropriate discovery request to supply to this method. As an alternative, consider usingengine(TestEngine)for a more fluent API.- Parameters:
testEngine- theTestEngineto use; must not benulldiscoveryRequest- theEngineDiscoveryRequestto use; must not benull- Returns:
- the recorded
EngineExecutionResults - Throws:
PreconditionViolationException- for invalid arguments- See Also:
execute(String, EngineDiscoveryRequest),engine(String),engine(TestEngine)
-
-