Search in sources :

Example 1 with TestEngineStub

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");
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngine(org.junit.platform.engine.TestEngine) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineStub(org.junit.platform.fakes.TestEngineStub) JUnitException(org.junit.platform.commons.JUnitException) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TestEngineStub

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);
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngine(org.junit.platform.engine.TestEngine) TestEngineStub(org.junit.platform.fakes.TestEngineStub) JUnitException(org.junit.platform.commons.JUnitException) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException)

Example 3 with TestEngineStub

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);
}
Also used : TestEngine(org.junit.platform.engine.TestEngine) TestEngineStub(org.junit.platform.fakes.TestEngineStub) Test(org.junit.jupiter.api.Test)

Example 4 with TestEngineStub

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 + "'");
}
Also used : LogRecord(java.util.logging.LogRecord) TestEngineStub(org.junit.platform.fakes.TestEngineStub) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TrackLogRecords(org.junit.jupiter.api.fixtures.TrackLogRecords)

Example 5 with TestEngineStub

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);
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngine(org.junit.platform.engine.TestEngine) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineStub(org.junit.platform.fakes.TestEngineStub) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TestEngineStub (org.junit.platform.fakes.TestEngineStub)6 TestEngine (org.junit.platform.engine.TestEngine)5 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)3 JUnitException (org.junit.platform.commons.JUnitException)2 PreconditionViolationException (org.junit.platform.commons.PreconditionViolationException)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 UniqueId (org.junit.platform.engine.UniqueId)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 LogRecord (java.util.logging.LogRecord)1 TrackLogRecords (org.junit.jupiter.api.fixtures.TrackLogRecords)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)1