Search in sources :

Example 81 with UniqueId

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

the class DefaultLauncherTests method discoverTestPlanForEngineThatThrowsAnErrorInDiscoverPhase.

@Test
void discoverTestPlanForEngineThatThrowsAnErrorInDiscoverPhase() {
    TestEngine engine = new TestEngineStub() {

        @Override
        public TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            throw new Error("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 82 with UniqueId

use of org.junit.platform.engine.UniqueId 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 83 with UniqueId

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

the class DemoHierarchicalTestEngine method addTest.

public DemoHierarchicalTestDescriptor addTest(Method testMethod, Runnable executeBlock) {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", testMethod.getName());
    MethodSource source = MethodSource.from(testMethod);
    DemoHierarchicalTestDescriptor child = new DemoHierarchicalTestDescriptor(uniqueId, testMethod.getName(), source, executeBlock);
    engineDescriptor.addChild(child);
    return child;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) MethodSource(org.junit.platform.engine.support.descriptor.MethodSource)

Example 84 with UniqueId

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

the class HierarchicalTestExecutorTests method executesDynamicTestDescriptors.

@Test
void executesDynamicTestDescriptors() throws Exception {
    UniqueId leafUniqueId = UniqueId.root("leaf", "child leaf");
    MyLeaf child = spy(new MyLeaf(leafUniqueId));
    MyLeaf dynamicTestDescriptor = spy(new MyLeaf(leafUniqueId.append("dynamic", "child")));
    when(child.execute(any(), any())).thenAnswer(invocation -> {
        DynamicTestExecutor dynamicTestExecutor = invocation.getArgument(1);
        dynamicTestExecutor.execute(dynamicTestDescriptor);
        return invocation.getArgument(0);
    });
    root.addChild(child);
    InOrder inOrder = inOrder(listener, root, child, dynamicTestDescriptor);
    executor.execute();
    ArgumentCaptor<TestExecutionResult> aTestExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
    inOrder.verify(listener).executionStarted(root);
    inOrder.verify(child).prepare(rootContext);
    inOrder.verify(child).shouldBeSkipped(rootContext);
    inOrder.verify(listener).executionStarted(child);
    inOrder.verify(child).execute(eq(rootContext), any());
    inOrder.verify(listener).dynamicTestRegistered(dynamicTestDescriptor);
    inOrder.verify(dynamicTestDescriptor).prepare(rootContext);
    inOrder.verify(dynamicTestDescriptor).shouldBeSkipped(rootContext);
    inOrder.verify(listener).executionStarted(dynamicTestDescriptor);
    inOrder.verify(dynamicTestDescriptor).execute(eq(rootContext), any());
    inOrder.verify(listener).executionFinished(eq(dynamicTestDescriptor), aTestExecutionResult.capture());
    inOrder.verify(listener).executionFinished(eq(child), aTestExecutionResult.capture());
    inOrder.verify(listener).executionFinished(eq(root), any(TestExecutionResult.class));
    assertThat(aTestExecutionResult.getAllValues()).extracting(TestExecutionResult::getStatus).containsExactly(SUCCESSFUL, SUCCESSFUL);
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) InOrder(org.mockito.InOrder) DynamicTestExecutor(org.junit.platform.engine.support.hierarchical.Node.DynamicTestExecutor) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 85 with UniqueId

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

the class LeafDescriptor method pruneGroup.

@Test
void pruneGroup() {
    final AtomicInteger countVisited = new AtomicInteger();
    TestDescriptor.Visitor visitor = descriptor -> {
        if (descriptor.getUniqueId().equals(UniqueId.root("group", "group1")))
            descriptor.removeFromHierarchy();
        countVisited.incrementAndGet();
    };
    engineDescriptor.accept(visitor);
    assertEquals(4, countVisited.get(), "Children of pruned element are not visited");
    List<UniqueId> visited = new ArrayList<>();
    engineDescriptor.accept(descriptor -> visited.add(descriptor.getUniqueId()));
    assertEquals(3, visited.size());
    assertFalse(visited.contains(UniqueId.root("group", "group1")));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) JUnitException(org.junit.platform.commons.JUnitException) Set(java.util.Set) UniqueId(org.junit.platform.engine.UniqueId) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestDescriptor(org.junit.platform.engine.TestDescriptor) UniqueId(org.junit.platform.engine.UniqueId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)131 Test (org.junit.jupiter.api.Test)95 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)83 DynamicTest (org.junit.jupiter.api.DynamicTest)64 TestDescriptor (org.junit.platform.engine.TestDescriptor)29 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)25 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)15 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)14 List (java.util.List)9 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)8 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)8 TestPlan (org.junit.platform.launcher.TestPlan)8 JUnitException (org.junit.platform.commons.JUnitException)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 Optional (java.util.Optional)6 DynamicDescendantFilter (org.junit.jupiter.engine.descriptor.DynamicDescendantFilter)6 TestEngine (org.junit.platform.engine.TestEngine)6 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5