use of org.junit.platform.fakes.TestEngineStub in project junit5 by junit-team.
the class DefaultLauncherTests method discoverErrorTestDescriptorForEngineThatThrowsInDiscoveryPhase.
@ParameterizedTest
@ValueSource(classes = { Error.class, RuntimeException.class })
void discoverErrorTestDescriptorForEngineThatThrowsInDiscoveryPhase(Class<? extends Throwable> throwableClass) {
TestEngine engine = new TestEngineStub("my-engine-id") {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
try {
var constructor = throwableClass.getDeclaredConstructor(String.class);
throw ExceptionUtils.throwAsUncheckedException(constructor.newInstance("ignored"));
} catch (Exception ignored) {
return null;
}
}
};
var launcher = createLauncher(engine);
var discoveryListener = mock(LauncherDiscoveryListener.class);
var request = //
request().listeners(//
discoveryListener).configurationParameter(DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME, //
"logging").build();
var testPlan = launcher.discover(request);
assertThat(testPlan.getRoots()).hasSize(1);
var engineIdentifier = getOnlyElement(testPlan.getRoots());
assertThat(getOnlyElement(testPlan.getRoots()).getDisplayName()).isEqualTo("my-engine-id");
verify(discoveryListener).launcherDiscoveryStarted(request);
verify(discoveryListener).launcherDiscoveryFinished(request);
assertDiscoveryFailed(engine, discoveryListener);
var listener = mock(TestExecutionListener.class);
launcher.execute(testPlan, listener);
var testExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
verify(listener).executionStarted(engineIdentifier);
verify(listener).executionFinished(eq(engineIdentifier), testExecutionResult.capture());
assertThat(testExecutionResult.getValue().getThrowable()).isPresent();
//
assertThat(testExecutionResult.getValue().getThrowable().get()).hasMessage("TestEngine with ID 'my-engine-id' failed to discover tests");
}
use of org.junit.platform.fakes.TestEngineStub in project junit5 by junit-team.
the class DefaultLauncherTests method assertImposter.
private void assertImposter(String id) {
TestEngine impostor = new TestEngineStub(id);
Exception exception = assertThrows(JUnitException.class, () -> createLauncher(impostor));
assertThat(exception).hasMessage("Third-party TestEngine '%s' is forbidden to use the reserved '%s' TestEngine ID.", impostor.getClass().getName(), id);
}
use of org.junit.platform.fakes.TestEngineStub in project junit5 by junit-team.
the class LauncherConfigTests method addTestEngines.
@Test
void addTestEngines() {
TestEngine first = new TestEngineStub();
TestEngine second = new TestEngineStub();
var config = LauncherConfig.builder().addTestEngines(first, second).build();
assertThat(config.getAdditionalTestEngines()).containsOnly(first, second);
}
use of org.junit.platform.fakes.TestEngineStub in project junit5 by junit-team.
the class DefaultLauncherTests method thirdPartyEngineUsingReservedEngineIdPrefixEmitsWarning.
@Test
@TrackLogRecords
void thirdPartyEngineUsingReservedEngineIdPrefixEmitsWarning(LogRecordListener listener) {
var id = "junit-using-reserved-prefix";
createLauncher(new TestEngineStub(id));
//
assertThat(listener.stream(EngineIdValidator.class, Level.WARNING).map(LogRecord::getMessage)).containsExactly("Third-party TestEngine implementations are forbidden to use the reserved 'junit-' prefix for their ID: '" + id + "'");
}
use of org.junit.platform.fakes.TestEngineStub 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);
}
Aggregations