Search in sources :

Example 11 with TestEngine

use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.

the class TestEngineTests method defaults.

@Test
void defaults() {
    TestEngine engine = new DefaultEngine();
    assertEquals(Optional.empty(), engine.getGroupId());
    assertEquals(Optional.empty(), engine.getArtifactId());
    assertEquals(Optional.of("DEVELOPMENT"), engine.getVersion());
}
Also used : TestEngine(org.junit.platform.engine.TestEngine) Test(org.junit.jupiter.api.Test)

Example 12 with TestEngine

use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.

the class EngineDiscoveryOrchestrator method discoverSafely.

private Map<TestEngine, TestDescriptor> discoverSafely(LauncherDiscoveryRequest request, Phase phase, LauncherDiscoveryListener listener, Function<String, UniqueId> uniqueIdCreator) {
    Map<TestEngine, TestDescriptor> testEngineDescriptors = new LinkedHashMap<>();
    for (TestEngine testEngine : this.testEngines) {
        boolean engineIsExcluded = // 
        request.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 %s phase.", testEngine.getId(), phase));
            continue;
        }
        logger.debug(() -> String.format("Discovering tests during Launcher %s phase in engine '%s'.", phase, testEngine.getId()));
        TestDescriptor rootDescriptor = discoverEngineRoot(testEngine, request, listener, uniqueIdCreator);
        testEngineDescriptors.put(testEngine, rootDescriptor);
    }
    List<PostDiscoveryFilter> filters = new LinkedList<>(postDiscoveryFilters);
    filters.addAll(request.getPostDiscoveryFilters());
    applyPostDiscoveryFilters(testEngineDescriptors, filters);
    prune(testEngineDescriptors);
    return testEngineDescriptors;
}
Also used : Filter.composeFilters(org.junit.platform.engine.Filter.composeFilters) FilterResult(org.junit.platform.engine.FilterResult) TestEngine(org.junit.platform.engine.TestEngine) Filter(org.junit.platform.engine.Filter) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) Function(java.util.function.Function) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) LinkedHashMap(java.util.LinkedHashMap) EngineDiscoveryResult(org.junit.platform.launcher.EngineDiscoveryResult) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) Collectors.toMap(java.util.stream.Collectors.toMap) Locale(java.util.Locale) Map(java.util.Map) LauncherDiscoveryListener(org.junit.platform.launcher.LauncherDiscoveryListener) LinkedList(java.util.LinkedList) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) Logger(org.junit.platform.commons.logging.Logger) Collection(java.util.Collection) JUnitException(org.junit.platform.commons.JUnitException) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) API(org.apiguardian.api.API) UniqueId(org.junit.platform.engine.UniqueId) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) UnrecoverableExceptions(org.junit.platform.commons.util.UnrecoverableExceptions) Entry(java.util.Map.Entry) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) TestEngine(org.junit.platform.engine.TestEngine) FilterResult(org.junit.platform.engine.FilterResult) TestDescriptor(org.junit.platform.engine.TestDescriptor) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with TestEngine

use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.

the class EngineExecutionOrchestrator method execute.

/**
 * Executes tests for the supplied {@linkplain LauncherDiscoveryResult
 * discovery results} and notifies the supplied {@linkplain
 * EngineExecutionListener listener} of execution events.
 */
public void execute(LauncherDiscoveryResult discoveryResult, EngineExecutionListener listener) {
    for (TestEngine testEngine : discoveryResult.getTestEngines()) {
        TestDescriptor engineDescriptor = discoveryResult.getEngineTestDescriptor(testEngine);
        if (engineDescriptor instanceof EngineDiscoveryErrorDescriptor) {
            listener.executionStarted(engineDescriptor);
            listener.executionFinished(engineDescriptor, TestExecutionResult.failed(((EngineDiscoveryErrorDescriptor) engineDescriptor).getCause()));
        } else {
            execute(engineDescriptor, listener, discoveryResult.getConfigurationParameters(), testEngine);
        }
    }
}
Also used : TestEngine(org.junit.platform.engine.TestEngine) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 14 with TestEngine

use of org.junit.platform.engine.TestEngine in project junit5 by junit-team.

the class LauncherConfigTests method preconditions.

@Test
void preconditions() {
    assertThrows(PreconditionViolationException.class, () -> LauncherConfig.builder().addTestEngines((TestEngine[]) null));
    assertThrows(PreconditionViolationException.class, () -> LauncherConfig.builder().addTestExecutionListeners((TestExecutionListener[]) null));
    TestEngine engine = new TestEngineStub();
    var listener = new TestExecutionListener() {
    };
    assertThrows(PreconditionViolationException.class, () -> LauncherConfig.builder().addTestEngines(engine, engine, null));
    assertThrows(PreconditionViolationException.class, () -> LauncherConfig.builder().addTestExecutionListeners(listener, listener, null));
}
Also used : TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestEngine(org.junit.platform.engine.TestEngine) TestEngineStub(org.junit.platform.fakes.TestEngineStub) Test(org.junit.jupiter.api.Test)

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