Search in sources :

Example 1 with TestExecutionResult

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

the class TreePrinter method colorCaption.

private String colorCaption(TreeNode node) {
    String caption = node.caption();
    if (node.result().isPresent()) {
        TestExecutionResult result = node.result().get();
        Color resultColor = Color.valueOf(result);
        if (result.getStatus() != Status.SUCCESSFUL) {
            return color(resultColor, caption);
        }
    }
    if (node.reason().isPresent()) {
        return color(SKIPPED, caption);
    }
    return color(Color.valueOf(node.identifier().orElseThrow(AssertionError::new)), caption);
}
Also used : TestExecutionResult(org.junit.platform.engine.TestExecutionResult)

Example 2 with TestExecutionResult

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

the class TreePrinter method printVisible.

private void printVisible(TreeNode node, String indent, boolean continuous) {
    String bullet = continuous ? theme.entry() : theme.end();
    String prefix = color(CONTAINER, indent + bullet);
    String tabbed = color(CONTAINER, indent + (continuous ? theme.vertical() : theme.blank()) + theme.blank());
    String caption = colorCaption(node);
    String duration = color(CONTAINER, node.duration + " ms");
    String icon = color(SKIPPED, theme.skipped());
    if (node.result().isPresent()) {
        TestExecutionResult result = node.result().get();
        Color resultColor = Color.valueOf(result);
        icon = color(resultColor, theme.status(result));
    }
    out.print(prefix);
    out.print(" ");
    out.print(caption);
    if (node.duration > 10000 && node.children.isEmpty()) {
        out.print(" ");
        out.print(duration);
    }
    out.print(" ");
    out.print(icon);
    node.result().ifPresent(result -> printThrowable(tabbed, result));
    node.reason().ifPresent(reason -> printMessage(SKIPPED, tabbed, reason));
    node.reports.forEach(e -> printReportEntry(tabbed, e));
    out.println();
}
Also used : TestExecutionResult(org.junit.platform.engine.TestExecutionResult)

Example 3 with TestExecutionResult

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

the class HierarchicalTestExecutorTests method exceptionInShouldBeSkippedAndCleanUp.

@Test
void exceptionInShouldBeSkippedAndCleanUp() throws Exception {
    RuntimeException shouldBeSkippedException = new RuntimeException("in prepare()");
    doThrow(shouldBeSkippedException).when(root).shouldBeSkipped(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);
    inOrder.verify(root).prepare(rootContext);
    inOrder.verify(root).shouldBeSkipped(rootContext);
    inOrder.verify(root).cleanUp(rootContext);
    inOrder.verify(listener).executionStarted(root);
    inOrder.verify(listener).executionFinished(eq(root), rootExecutionResult.capture());
    inOrder.verifyNoMoreInteractions();
    assertThat(rootExecutionResult.getValue().getStatus()).isEqualTo(FAILED);
    assertThat(rootExecutionResult.getValue().getThrowable()).containsSame(shouldBeSkippedException);
    assertThat(shouldBeSkippedException.getSuppressed()).containsExactly(cleanUpException);
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 4 with TestExecutionResult

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

the class HierarchicalTestExecutorTests method exceptionInShouldBeSkipped.

@Test
void exceptionInShouldBeSkipped() throws Exception {
    MyContainer child = spy(new MyContainer(UniqueId.root("container", "child container")));
    RuntimeException anException = new RuntimeException("in skip");
    when(child.shouldBeSkipped(rootContext)).thenThrow(anException);
    root.addChild(child);
    InOrder inOrder = inOrder(listener, child);
    executor.execute();
    ArgumentCaptor<TestExecutionResult> childExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
    inOrder.verify(listener).executionStarted(root);
    inOrder.verify(child).prepare(rootContext);
    inOrder.verify(child).shouldBeSkipped(rootContext);
    inOrder.verify(child).cleanUp(rootContext);
    inOrder.verify(listener).executionStarted(child);
    inOrder.verify(listener).executionFinished(eq(child), childExecutionResult.capture());
    inOrder.verify(listener).executionFinished(eq(root), any(TestExecutionResult.class));
    verifyNoMoreInteractions(child);
    assertThat(childExecutionResult.getValue().getStatus()).isEqualTo(FAILED);
    assertThat(childExecutionResult.getValue().getThrowable()).containsSame(anException);
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 5 with TestExecutionResult

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

the class HierarchicalTestExecutorTests method exceptionInContainerBeforeAll.

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

Aggregations

TestExecutionResult (org.junit.platform.engine.TestExecutionResult)48 Test (org.junit.jupiter.api.Test)41 TestIdentifier (org.junit.platform.launcher.TestIdentifier)15 InOrder (org.mockito.InOrder)15 TestPlan (org.junit.platform.launcher.TestPlan)14 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 Launcher (org.junit.platform.launcher.Launcher)5 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)5 LinkedHashMap (java.util.LinkedHashMap)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