Search in sources :

Example 26 with TestExecutionResult

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

the class VintageLauncherIntegrationTests method executesOnlyNotExcludedTaggedMethodOfNestedTestClass.

@Test
void executesOnlyNotExcludedTaggedMethodOfNestedTestClass() {
    Class<?> testClass = EnclosedJUnit4TestCase.class;
    Class<?> nestedTestClass = EnclosedJUnit4TestCase.NestedClass.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(excludeTags(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(), "successfulTest");
}
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)

Example 27 with TestExecutionResult

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

the class VintageLauncherIntegrationTests method removesCompleteClassIfNoMethodHasMatchingTags.

@Test
void removesCompleteClassIfNoMethodHasMatchingTags() {
    Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(includeTags("wrong-tag"));
    TestPlan testPlan = discover(request);
    assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).isEmpty();
    Map<TestIdentifier, TestExecutionResult> results = execute(request);
    // 
    assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactly("JUnit Vintage");
}
Also used : LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 28 with TestExecutionResult

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

the class VintageLauncherIntegrationTests method executesAllTestsForNotFilterableRunner.

@TrackLogRecords
@Test
void executesAllTestsForNotFilterableRunner(LogRecordListener logRecordListener) {
    Class<?> testClass = JUnit4TestCaseWithNotFilterableRunner.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters((PostDiscoveryFilter) descriptor -> includedIf(descriptor.getDisplayName().contains("#1")));
    TestPlan testPlan = discover(request);
    logRecordListener.clear();
    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(), "Test #0", "Test #1");
    // 
    assertThat(logRecordListener.stream(RunnerTestDescriptor.class, Level.WARNING).map(LogRecord::getMessage)).containsExactly(// 
    "Runner " + NotFilterableRunner.class.getName() + " (used on class " + testClass.getName() + ")" + " does not support filtering and will therefore be run completely.");
}
Also used : JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) ParameterizedTestCase(org.junit.vintage.engine.samples.junit4.ParameterizedTestCase) Launcher(org.junit.platform.launcher.Launcher) TestPlan(org.junit.platform.launcher.TestPlan) JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) TagFilter.excludeTags(org.junit.platform.launcher.TagFilter.excludeTags) Categories(org.junit.vintage.engine.samples.junit4.Categories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiscoverySelectors.selectClass(org.junit.platform.engine.discovery.DiscoverySelectors.selectClass) FilterResult.includedIf(org.junit.platform.engine.FilterResult.includedIf) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Level(java.util.logging.Level) LinkedHashMap(java.util.LinkedHashMap) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) ENGINE_ID(org.junit.vintage.engine.descriptor.VintageTestDescriptor.ENGINE_ID) Map(java.util.Map) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords) LauncherFactory(org.junit.platform.launcher.core.LauncherFactory) NotFilterableRunner(org.junit.vintage.engine.samples.junit4.NotFilterableRunner) JUnit4SuiteOfSuiteWithFilterableChildRunner(org.junit.vintage.engine.samples.junit4.JUnit4SuiteOfSuiteWithFilterableChildRunner) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) PlainJUnit4TestCaseWithTwoTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) EnclosedJUnit4TestCase(org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) LogRecord(java.util.logging.LogRecord) JUnit4SuiteWithTwoTestCases(org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithTwoTestCases) Test(org.junit.jupiter.api.Test) LogRecordListener(org.junit.platform.commons.logging.LogRecordListener) TestIdentifier(org.junit.platform.launcher.TestIdentifier) FilterResult.excluded(org.junit.platform.engine.FilterResult.excluded) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) Suite(org.junit.runners.Suite) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) TagFilter.includeTags(org.junit.platform.launcher.TagFilter.includeTags) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) TestPlan(org.junit.platform.launcher.TestPlan) LogRecord(java.util.logging.LogRecord) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 29 with TestExecutionResult

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

the class HierarchicalTestExecutorTests method abortInContainerBeforeAll.

@Test
void abortInContainerBeforeAll() throws Exception {
    MyContainer child = spy(new MyContainer(UniqueId.root("container", "child container")));
    root.addChild(child);
    TestAbortedException anAbortedException = new TestAbortedException("in BeforeAll");
    when(root.before(rootContext)).thenThrow(anAbortedException);
    InOrder inOrder = inOrder(listener, root, child);
    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(ABORTED);
    assertThat(rootExecutionResult.getValue().getThrowable()).containsSame(anAbortedException);
    verifyNoMoreInteractions(child);
}
Also used : InOrder(org.mockito.InOrder) TestAbortedException(org.opentest4j.TestAbortedException) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 30 with TestExecutionResult

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

the class HierarchicalTestExecutorTests method exceptionInPrepare.

@Test
void exceptionInPrepare() throws Exception {
    RuntimeException prepareException = new RuntimeException("in prepare()");
    doThrow(prepareException).when(root).prepare(rootContext);
    executor.execute();
    ArgumentCaptor<TestExecutionResult> rootExecutionResult = ArgumentCaptor.forClass(TestExecutionResult.class);
    InOrder inOrder = inOrder(listener, root);
    inOrder.verify(root).prepare(rootContext);
    inOrder.verify(listener).executionStarted(root);
    inOrder.verify(listener).executionFinished(eq(root), rootExecutionResult.capture());
    inOrder.verifyNoMoreInteractions();
    assertThat(rootExecutionResult.getValue().getStatus()).isEqualTo(FAILED);
    assertThat(rootExecutionResult.getValue().getThrowable()).containsSame(prepareException);
    assertThat(prepareException.getSuppressed()).isEmpty();
}
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