use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.
the class DefaultLauncherTests method discoverTestPlanForEngineThatThrowsRuntimeExceptionInDiscoverPhase.
@Test
void discoverTestPlanForEngineThatThrowsRuntimeExceptionInDiscoverPhase() {
TestEngine engine = new TestEngineStub() {
@Override
public TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
throw new RuntimeException("ignored");
}
};
TestPlan testPlan = createLauncher(engine).discover(request().build());
assertThat(testPlan.getRoots()).hasSize(0);
}
use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.
the class DefaultLauncher method discoverRoot.
private Root discoverRoot(LauncherDiscoveryRequest discoveryRequest, String phase) {
Root root = new Root();
for (TestEngine testEngine : this.testEngines) {
// @formatter:off
boolean engineIsExcluded = discoveryRequest.getEngineFilters().stream().map(engineFilter -> engineFilter.apply(testEngine)).anyMatch(FilterResult::excluded);
if (engineIsExcluded) {
logger.debug(() -> String.format("Test discovery for engine '%s' was skipped due to an EngineFilter in phase '%s'.", testEngine.getId(), phase));
continue;
}
logger.debug(() -> String.format("Discovering tests during Launcher %s phase in engine '%s'.", phase, testEngine.getId()));
Optional<TestDescriptor> engineRoot = discoverEngineRoot(testEngine, discoveryRequest);
engineRoot.ifPresent(rootDescriptor -> root.add(testEngine, rootDescriptor));
}
root.applyPostDiscoveryFilters(discoveryRequest);
root.prune();
return root;
}
use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.
the class DefaultLauncherTests method testPlanThrowsExceptionWhenModified.
@Test
@SuppressWarnings("deprecation")
void testPlanThrowsExceptionWhenModified() {
TestEngine engine = new TestEngineSpy();
var launcher = createLauncher(engine);
var testPlan = launcher.discover(request().build());
var engineIdentifier = getOnlyElement(testPlan.getRoots());
var engineUniqueId = UniqueId.parse(engineIdentifier.getUniqueId());
assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1);
var addedIdentifier = TestIdentifier.from(new TestDescriptorStub(engineUniqueId.append("test", "test2"), "test2"));
var exception = assertThrows(JUnitException.class, () -> testPlan.add(addedIdentifier));
assertThat(exception).hasMessage("Unsupported attempt to modify the TestPlan was detected. " + "Please contact your IDE/tool vendor and request a fix or downgrade to JUnit 5.7.x (see https://github.com/junit-team/junit5/issues/1732 for details).");
assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1).doesNotContain(addedIdentifier);
}
use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.
the class DefaultLauncherTests method discoverTestPlanForEngineThatReturnsNullForItsRootDescriptor.
@Test
void discoverTestPlanForEngineThatReturnsNullForItsRootDescriptor() {
TestEngine engine = new TestEngineStub("some-engine-id") {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
return null;
}
};
var discoveryListener = mock(LauncherDiscoveryListener.class);
var testPlan = createLauncher(engine).discover(//
request().listeners(//
discoveryListener).configurationParameter(DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME, //
"logging").build());
assertThat(testPlan.getRoots()).hasSize(1);
assertDiscoveryFailed(engine, discoveryListener);
}
use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.
the class VintageTestEngineExecutionTests method execute.
private static void execute(Class<?> testClass, EngineExecutionListener listener) {
TestEngine testEngine = new VintageTestEngine();
var discoveryRequest = request(testClass);
var engineTestDescriptor = testEngine.discover(discoveryRequest, UniqueId.forEngine(testEngine.getId()));
testEngine.execute(new ExecutionRequest(engineTestDescriptor, listener, discoveryRequest.getConfigurationParameters()));
}
Aggregations