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