Search in sources :

Example 6 with TestExecutionResult

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);
}
Also used : InOrder(org.mockito.InOrder) TestAbortedException(org.opentest4j.TestAbortedException) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 7 with TestExecutionResult

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);
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 8 with TestExecutionResult

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());
}
Also used : TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 9 with TestExecutionResult

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());
}
Also used : TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 10 with TestExecutionResult

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");
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) Categories(org.junit.vintage.engine.samples.junit4.Categories) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) EnclosedJUnit4TestCase(org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Aggregations

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