Search in sources :

Example 36 with TestExecutionResult

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

the class HierarchicalTestExecutorTests method exceptionInContainerAfterAllAndCleanUp.

@Test
void exceptionInContainerAfterAllAndCleanUp() throws Exception {
    MyLeaf child = spy(new MyLeaf(UniqueId.root("leaf", "child container")));
    root.addChild(child);
    RuntimeException afterException = new RuntimeException("in after()");
    doThrow(afterException).when(root).after(rootContext);
    RuntimeException cleanUpException = new RuntimeException("in cleanUp()");
    doThrow(cleanUpException).when(root).cleanUp(rootContext);
    executor.execute();
    ArgumentCaptor<TestExecutionResult> rootExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
    InOrder inOrder = inOrder(listener, root, child);
    inOrder.verify(root).prepare(rootContext);
    inOrder.verify(root).shouldBeSkipped(rootContext);
    inOrder.verify(listener).executionStarted(root);
    inOrder.verify(root).before(rootContext);
    inOrder.verify(listener).executionStarted(child);
    inOrder.verify(child).execute(eq(rootContext), any());
    inOrder.verify(listener).executionFinished(eq(child), any(TestExecutionResult.class));
    inOrder.verify(root).after(rootContext);
    inOrder.verify(root).cleanUp(rootContext);
    inOrder.verify(listener).executionFinished(eq(root), rootExecutionResult.capture());
    inOrder.verifyNoMoreInteractions();
    assertThat(rootExecutionResult.getValue().getStatus()).isEqualTo(FAILED);
    assertThat(rootExecutionResult.getValue().getThrowable()).containsSame(afterException);
    assertThat(afterException.getSuppressed()).containsExactly(cleanUpException);
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 37 with TestExecutionResult

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

the class HierarchicalTestExecutorTests method exceptionInCleanUp.

@Test
void exceptionInCleanUp() throws Exception {
    RuntimeException cleanUpException = new RuntimeException("in cleanUp()");
    doThrow(cleanUpException).when(root).cleanUp(rootContext);
    executor.execute();
    ArgumentCaptor<TestExecutionResult> rootExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
    InOrder inOrder = inOrder(listener, root);
    inOrder.verify(root).prepare(rootContext);
    inOrder.verify(root).shouldBeSkipped(rootContext);
    inOrder.verify(listener).executionStarted(root);
    inOrder.verify(root).execute(eq(rootContext), any());
    inOrder.verify(root).after(rootContext);
    inOrder.verify(root).cleanUp(rootContext);
    inOrder.verify(listener).executionFinished(eq(root), rootExecutionResult.capture());
    inOrder.verifyNoMoreInteractions();
    assertThat(rootExecutionResult.getValue().getStatus()).isEqualTo(FAILED);
    assertThat(rootExecutionResult.getValue().getThrowable()).containsSame(cleanUpException);
    assertThat(cleanUpException.getSuppressed()).isEmpty();
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 38 with TestExecutionResult

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

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

the class SingleTestExecutorTests method executeSafelyFailed.

@Test
void executeSafelyFailed() {
    AssertionError assertionError = new AssertionError("assumption violated");
    TestExecutionResult result = new SingleTestExecutor().executeSafely(() -> {
        throw assertionError;
    });
    assertEquals(FAILED, result.getStatus());
    assertSame(assertionError, result.getThrowable().get());
}
Also used : TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 40 with TestExecutionResult

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

the class SingleTestExecutorTests method executeSafelyAborted.

@Test
void executeSafelyAborted() {
    TestAbortedException testAbortedException = new TestAbortedException("assumption violated");
    TestExecutionResult result = new SingleTestExecutor().executeSafely(() -> {
        throw testAbortedException;
    });
    assertEquals(ABORTED, result.getStatus());
    assertSame(testAbortedException, result.getThrowable().get());
}
Also used : TestAbortedException(org.opentest4j.TestAbortedException) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Aggregations

TestExecutionResult (org.junit.platform.engine.TestExecutionResult)40 Test (org.junit.jupiter.api.Test)34 InOrder (org.mockito.InOrder)15 TestPlan (org.junit.platform.launcher.TestPlan)14 TestIdentifier (org.junit.platform.launcher.TestIdentifier)13 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 LinkedHashMap (java.util.LinkedHashMap)4 Launcher (org.junit.platform.launcher.Launcher)4 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)4 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)4 JUnit4SuiteWithTwoTestCases (org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithTwoTestCases)4 JUnit4TestCaseWithNotFilterableRunner (org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner)4 Map (java.util.Map)3 Level (java.util.logging.Level)3 LogRecord (java.util.logging.LogRecord)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)3