use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.
the class HierarchicalTestExecutorTests method exceptionInAfterDoesNotHideEarlierException.
@Test
void exceptionInAfterDoesNotHideEarlierException() throws Exception {
MyLeaf child = spy(new MyLeaf(UniqueId.root("leaf", "leaf")));
Exception exceptionInExecute = new RuntimeException("execute");
Exception exceptionInAfter = new RuntimeException("after");
doThrow(exceptionInExecute).when(child).execute(eq(rootContext), any());
doThrow(exceptionInAfter).when(child).after(eq(rootContext));
root.addChild(child);
InOrder inOrder = inOrder(listener, child);
executor.execute();
ArgumentCaptor<TestExecutionResult> childExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
inOrder.verify(child).execute(eq(rootContext), any());
inOrder.verify(child).after(eq(rootContext));
inOrder.verify(listener).executionFinished(eq(child), childExecutionResult.capture());
assertThat(childExecutionResult.getValue().getStatus()).isEqualTo(FAILED);
assertThat(childExecutionResult.getValue().getThrowable().get()).isSameAs(exceptionInExecute).hasSuppressedException(exceptionInAfter);
}
use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.
the class HierarchicalTestExecutorTests method executesDynamicTestDescriptorsUsingContainerAndTestType.
@Test
void executesDynamicTestDescriptorsUsingContainerAndTestType() throws Exception {
MyContainerAndTest child = spy(new MyContainerAndTest(root.getUniqueId().append("c&t", "child")));
MyContainerAndTest dynamicContainerAndTest = spy(new MyContainerAndTest(child.getUniqueId().append("c&t", "dynamicContainerAndTest")));
MyLeaf dynamicLeaf = spy(new MyLeaf(dynamicContainerAndTest.getUniqueId().append("test", "dynamicLeaf")));
root.addChild(child);
when(child.execute(any(), any())).thenAnswer(registerAndExecute(dynamicContainerAndTest));
when(dynamicContainerAndTest.execute(any(), any())).thenAnswer(registerAndExecute(dynamicLeaf));
when(dynamicLeaf.execute(any(), any())).thenAnswer(invocation -> {
throw new AssertionError("test fails");
});
InOrder inOrder = inOrder(listener, root, child, dynamicContainerAndTest, dynamicLeaf);
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(dynamicContainerAndTest);
inOrder.verify(dynamicContainerAndTest).prepare(rootContext);
inOrder.verify(dynamicContainerAndTest).shouldBeSkipped(rootContext);
inOrder.verify(listener).executionStarted(dynamicContainerAndTest);
inOrder.verify(dynamicContainerAndTest).execute(eq(rootContext), any());
inOrder.verify(listener).dynamicTestRegistered(dynamicLeaf);
inOrder.verify(dynamicLeaf).prepare(rootContext);
inOrder.verify(dynamicLeaf).shouldBeSkipped(rootContext);
inOrder.verify(listener).executionStarted(dynamicLeaf);
inOrder.verify(dynamicLeaf).execute(eq(rootContext), any());
inOrder.verify(listener).executionFinished(eq(dynamicLeaf), aTestExecutionResult.capture());
inOrder.verify(listener).executionFinished(eq(dynamicContainerAndTest), 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(FAILED, SUCCESSFUL, SUCCESSFUL);
}
use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.
the class SingleTestExecutorTests method executeSafelySuccessful.
@Test
void executeSafelySuccessful() {
TestExecutionResult result = new SingleTestExecutor().executeSafely(() -> {
});
assertEquals(SUCCESSFUL, result.getStatus());
assertEquals(Optional.empty(), result.getThrowable());
}
use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.
the class TreePrinterTests method printNodeHandlesNullMessageThrowableGracefully.
@Test
// https://github.com/junit-team/junit5/issues/786
void printNodeHandlesNullMessageThrowableGracefully() {
TestExecutionResult result = TestExecutionResult.failed(new NullPointerException());
TreeNode node = new TreeNode(createEngineId("NPE", "test()")).setResult(result);
new TreePrinter(out, Theme.ASCII, true).print(node);
assertLinesMatch(Arrays.asList(".", "+-- test() [X] java.lang.NullPointerException"), actual());
}
use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.
the class VintageLauncherIntegrationTests method executesIncludedTaggedMethodOfNestedTestClass.
@Test
void executesIncludedTaggedMethodOfNestedTestClass() {
Class<?> testClass = EnclosedJUnit4TestCase.class;
Class<?> nestedTestClass = EnclosedJUnit4TestCase.NestedClass.class;
LauncherDiscoveryRequestBuilder request = //
request().selectors(//
selectClass(testClass)).filters(includeTags(Categories.Failing.class.getName()));
TestPlan testPlan = discover(request);
assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).hasSize(3);
Map<TestIdentifier, TestExecutionResult> results = execute(request);
//
assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage", testClass.getName(), nestedTestClass.getName(), "failingTest");
}
Aggregations