Search in sources :

Example 26 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesPackageSelectorForJUnit3SamplesPackage.

@Test
void resolvesPackageSelectorForJUnit3SamplesPackage() {
    Class<?> testClass = PlainJUnit3TestCaseWithSingleTestWhichFails.class;
    LauncherDiscoveryRequest discoveryRequest = request().selectors(selectPackage(testClass.getPackage().getName())).build();
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    // @formatter:off
    assertThat(engineDescriptor.getChildren()).extracting(TestDescriptor::getDisplayName).contains(testClass.getName()).doesNotContain(PlainJUnit4TestCaseWithSingleTestWhichFails.class.getName());
// @formatter:on
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) PlainJUnit3TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit3.PlainJUnit3TestCaseWithSingleTestWhichFails) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 27 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesCombinationOfMethodAndUniqueIdSelector.

@Test
void resolvesCombinationOfMethodAndUniqueIdSelector() throws Exception {
    Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
    LauncherDiscoveryRequest discoveryRequest = // 
    request().selectors(// 
    selectMethod(testClass, testClass.getMethod("failingTest")), selectUniqueId(// 
    VintageUniqueIdBuilder.uniqueIdForMethod(testClass, "abortedTest"))).build();
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertRunnerTestDescriptor(runnerDescriptor, testClass);
    List<TestDescriptor> testMethodDescriptors = new ArrayList<>(runnerDescriptor.getChildren());
    assertThat(testMethodDescriptors).hasSize(2);
    assertTestMethodDescriptor(testMethodDescriptors.get(0), testClass, "abortedTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
    assertTestMethodDescriptor(testMethodDescriptors.get(1), testClass, "failingTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ArrayList(java.util.ArrayList) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 28 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesJUnit3TestCase.

@Test
void resolvesJUnit3TestCase() throws Exception {
    Class<?> testClass = PlainJUnit3TestCaseWithSingleTestWhichFails.class;
    LauncherDiscoveryRequest discoveryRequest = discoveryRequestForClass(testClass);
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertRunnerTestDescriptor(runnerDescriptor, testClass);
    TestDescriptor childDescriptor = getOnlyElement(runnerDescriptor.getChildren());
    assertTestMethodDescriptor(childDescriptor, testClass, "test", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) PlainJUnit3TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit3.PlainJUnit3TestCaseWithSingleTestWhichFails) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 29 with TestDescriptor

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

the class VintageTestEngineDiscoveryTests method resolvesCategoriesIntoTags.

@Test
void resolvesCategoriesIntoTags() {
    Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
    LauncherDiscoveryRequest discoveryRequest = discoveryRequestForClass(testClass);
    TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
    TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
    assertThat(runnerDescriptor.getTags()).containsOnly(TestTag.create(Plain.class.getName()));
    TestDescriptor failingTest = findChildByDisplayName(runnerDescriptor, "failingTest");
    // 
    assertThat(failingTest.getTags()).containsOnly(// 
    TestTag.create(Plain.class.getName()), TestTag.create(Failing.class.getName()));
    TestDescriptor ignoredWithoutReason = findChildByDisplayName(runnerDescriptor, "ignoredTest1_withoutReason");
    // 
    assertThat(ignoredWithoutReason.getTags()).containsOnly(// 
    TestTag.create(Plain.class.getName()), TestTag.create(Skipped.class.getName()));
    TestDescriptor ignoredWithReason = findChildByDisplayName(runnerDescriptor, "ignoredTest2_withReason");
    // 
    assertThat(ignoredWithReason.getTags()).containsOnly(// 
    TestTag.create(Plain.class.getName()), // 
    TestTag.create(Skipped.class.getName()), TestTag.create(SkippedWithReason.class.getName()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 30 with TestDescriptor

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

the class VintageTestEngineExecutionTests method reportsExecutionEventsAroundLifecycleMethods.

@Test
void reportsExecutionEventsAroundLifecycleMethods() {
    Class<?> testClass = PlainJUnit4TestCaseWithLifecycleMethods.class;
    PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.clear();
    EngineExecutionListener listener = new EngineExecutionListener() {

        @Override
        public void executionStarted(TestDescriptor testDescriptor) {
            PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.add("executionStarted:" + testDescriptor.getDisplayName());
        }

        @Override
        public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) {
            PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.add("executionFinished:" + testDescriptor.getDisplayName());
        }

        @Override
        public void executionSkipped(TestDescriptor testDescriptor, String reason) {
            PlainJUnit4TestCaseWithLifecycleMethods.EVENTS.add("executionSkipped:" + testDescriptor.getDisplayName());
        }

        @Override
        public void dynamicTestRegistered(TestDescriptor testDescriptor) {
        }

        @Override
        public void reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry) {
        }
    };
    execute(testClass, listener);
    // @formatter:off
    assertThat(PlainJUnit4TestCaseWithLifecycleMethods.EVENTS).containsExactly("executionStarted:JUnit Vintage", "executionStarted:" + testClass.getName(), "beforeClass", "executionStarted:failingTest", "before", "failingTest", "after", "executionFinished:failingTest", "executionSkipped:skippedTest", "executionStarted:succeedingTest", "before", "succeedingTest", "after", "executionFinished:succeedingTest", "afterClass", "executionFinished:" + testClass.getName(), "executionFinished:JUnit Vintage");
// @formatter:on
}
Also used : PlainJUnit4TestCaseWithLifecycleMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithLifecycleMethods) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ReportEntry(org.junit.platform.engine.reporting.ReportEntry) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Aggregations

TestDescriptor (org.junit.platform.engine.TestDescriptor)143 Test (org.junit.jupiter.api.Test)103 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)58 UniqueId (org.junit.platform.engine.UniqueId)33 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)31 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)19 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)17 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)14 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Set (java.util.Set)11 DynamicTest (org.junit.jupiter.api.DynamicTest)11 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)11 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)11 Optional (java.util.Optional)10 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)9 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)9