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