Search in sources :

Example 31 with TestExecutionResult

use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.

the class HierarchicalTestExecutorTests method abortInLeafExecute.

@Test
void abortInLeafExecute() throws Exception {
    MyLeaf child = spy(new MyLeaf(UniqueId.root("leaf", "leaf")));
    TestAbortedException anAbortedException = new TestAbortedException("in test");
    when(child.execute(eq(rootContext), any())).thenThrow(anAbortedException);
    root.addChild(child);
    InOrder inOrder = inOrder(listener, root, child);
    executor.execute();
    ArgumentCaptor<TestExecutionResult> childExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
    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), childExecutionResult.capture());
    inOrder.verify(root).after(rootContext);
    inOrder.verify(listener).executionFinished(eq(root), any(TestExecutionResult.class));
    assertThat(childExecutionResult.getValue().getStatus()).isEqualTo(ABORTED);
    assertThat(childExecutionResult.getValue().getThrowable()).containsSame(anAbortedException);
}
Also used : InOrder(org.mockito.InOrder) TestAbortedException(org.opentest4j.TestAbortedException) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 32 with TestExecutionResult

use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.

the class HierarchicalTestExecutorTests method rootDescriptorWithOneChildContainer.

@Test
void rootDescriptorWithOneChildContainer() throws Exception {
    MyContainer child = spy(new MyContainer(UniqueId.root("container", "child container")));
    root.addChild(child);
    InOrder inOrder = inOrder(listener, root, 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(listener).executionStarted(child);
    inOrder.verify(child).before(rootContext);
    inOrder.verify(child).after(rootContext);
    inOrder.verify(listener).executionFinished(eq(child), childExecutionResult.capture());
    inOrder.verify(listener).executionFinished(eq(root), any(TestExecutionResult.class));
    assertThat(childExecutionResult.getValue().getStatus()).isEqualTo(SUCCESSFUL);
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 33 with TestExecutionResult

use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.

the class HierarchicalTestExecutorTests method rootDescriptorWithOneChildLeaf.

@Test
void rootDescriptorWithOneChildLeaf() throws Exception {
    MyLeaf child = spy(new MyLeaf(UniqueId.root("leaf", "child leaf")));
    root.addChild(child);
    InOrder inOrder = inOrder(listener, root, child);
    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).executionFinished(eq(child), aTestExecutionResult.capture());
    inOrder.verify(listener).executionFinished(eq(root), any(TestExecutionResult.class));
    assertThat(aTestExecutionResult.getValue().getStatus()).isEqualTo(SUCCESSFUL);
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 34 with TestExecutionResult

use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.

the class HierarchicalTestExecutorTests method emptyRootDescriptor.

@Test
void emptyRootDescriptor() throws Exception {
    InOrder inOrder = inOrder(listener, root);
    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(SUCCESSFUL);
}
Also used : InOrder(org.mockito.InOrder) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 35 with TestExecutionResult

use of org.junit.platform.engine.TestExecutionResult in project junit5 by junit-team.

the class HierarchicalTestExecutorTests method exceptionInLeafExecute.

@Test
void exceptionInLeafExecute() throws Exception {
    MyLeaf child = spy(new MyLeaf(UniqueId.root("leaf", "leaf")));
    RuntimeException anException = new RuntimeException("in test");
    when(child.execute(eq(rootContext), any())).thenThrow(anException);
    root.addChild(child);
    InOrder inOrder = inOrder(listener, root, child);
    executor.execute();
    ArgumentCaptor<TestExecutionResult> childExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
    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), childExecutionResult.capture());
    inOrder.verify(root).after(rootContext);
    inOrder.verify(listener).executionFinished(eq(root), any(TestExecutionResult.class));
    assertThat(childExecutionResult.getValue().getStatus()).isEqualTo(FAILED);
    assertThat(childExecutionResult.getValue().getThrowable()).containsSame(anException);
}
Also used : InOrder(org.mockito.InOrder) 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