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());
}
use of org.junit.platform.engine.TestExecutionResult in project mockito by mockito.
the class StrictnessTest method session_checks_for_strict_stubs.
@Test
void session_checks_for_strict_stubs() {
TestExecutionResult result = invokeTestClassAndRetrieveMethodResult(StrictStubs.class);
assertThat(result.getStatus()).isEqualTo(TestExecutionResult.Status.FAILED);
assertThat(result.getThrowable().get()).isInstanceOf(UnnecessaryStubbingException.class);
}
Aggregations