Search in sources :

Example 6 with TestEngine

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

Example 7 with TestEngine

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;
}
Also used : Preconditions(org.junit.platform.commons.util.Preconditions) Launcher(org.junit.platform.launcher.Launcher) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestPlan(org.junit.platform.launcher.TestPlan) Logger(org.junit.platform.commons.logging.Logger) JUnitException(org.junit.platform.commons.JUnitException) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) FilterResult(org.junit.platform.engine.FilterResult) TestEngine(org.junit.platform.engine.TestEngine) Set(java.util.Set) BlacklistedExceptions(org.junit.platform.commons.util.BlacklistedExceptions) UniqueId(org.junit.platform.engine.UniqueId) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) HashSet(java.util.HashSet) Optional(java.util.Optional) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestEngine(org.junit.platform.engine.TestEngine) FilterResult(org.junit.platform.engine.FilterResult) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 8 with TestEngine

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);
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngine(org.junit.platform.engine.TestEngine) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) TestEngineSpy(org.junit.platform.fakes.TestEngineSpy) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with TestEngine

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);
}
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)

Example 10 with TestEngine

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()));
}
Also used : TestEngine(org.junit.platform.engine.TestEngine) ExecutionRequest(org.junit.platform.engine.ExecutionRequest)

Aggregations

TestEngine (org.junit.platform.engine.TestEngine)14 Test (org.junit.jupiter.api.Test)7 UniqueId (org.junit.platform.engine.UniqueId)6 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)6 TestEngineStub (org.junit.platform.fakes.TestEngineStub)5 JUnitException (org.junit.platform.commons.JUnitException)4 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)4 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)4 TestPlan (org.junit.platform.launcher.TestPlan)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)3 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)3 Optional (java.util.Optional)2 PreconditionViolationException (org.junit.platform.commons.PreconditionViolationException)2 Logger (org.junit.platform.commons.logging.Logger)2 LoggerFactory (org.junit.platform.commons.logging.LoggerFactory)2 FilterResult (org.junit.platform.engine.FilterResult)2 TestEngineStub (org.junit.platform.engine.test.TestEngineStub)2 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)2