Search in sources :

Example 21 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project junit5 by junit-team.

the class VintageLauncherIntegrationTests method removesCompleteClassWithNotFilterableRunnerIfItHasExcludedTag.

@Test
void removesCompleteClassWithNotFilterableRunnerIfItHasExcludedTag() {
    Class<?> testClass = JUnit4TestCaseWithNotFilterableRunner.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(excludeTags(Categories.Successful.class.getName()));
    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 : JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) 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) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 22 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project mockito by mockito.

the class StrictnessTest method invokeTestClassAndRetrieveMethodResult.

private TestExecutionResult invokeTestClassAndRetrieveMethodResult(Class<?> clazz) {
    LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectClass(clazz)).build();
    Launcher launcher = LauncherFactory.create();
    final TestExecutionResult[] result = new TestExecutionResult[1];
    launcher.registerTestExecutionListeners(new TestExecutionListener() {

        @Override
        public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
            if (testIdentifier.getDisplayName().endsWith("()")) {
                result[0] = testExecutionResult;
            }
        }
    });
    launcher.execute(request);
    return result[0];
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) Launcher(org.junit.platform.launcher.Launcher) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult)

Example 23 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project gradle by gradle.

the class JUnitPlatformTestExecutionListener method createTestDescriptor.

private TestDescriptorInternal createTestDescriptor(TestIdentifier test, String name, String displayName) {
    TestIdentifier classIdentifier = findTestClassIdentifier(test);
    String className = className(classIdentifier);
    String classDisplayName = classDisplayName(classIdentifier);
    return new DefaultTestDescriptor(idGenerator.generateId(), className, name, classDisplayName, displayName);
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) DefaultTestDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestDescriptor)

Example 24 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project junit5 by junit-team.

the class OverloadedTestMethodTests method executeTestCaseWithOverloadedMethodsAndThenRerunOnlyOneOfTheMethodsSelectedByUniqueId.

@Test
void executeTestCaseWithOverloadedMethodsAndThenRerunOnlyOneOfTheMethodsSelectedByUniqueId() {
    Events tests = executeTestsForClass(TestCase.class).testEvents();
    tests.assertStatistics(stats -> stats.started(2).succeeded(2).failed(0));
    Optional<Event> first = tests.succeeded().filter(event -> event.getTestDescriptor().getUniqueId().toString().contains(TestInfo.class.getName())).findFirst();
    assertTrue(first.isPresent());
    TestIdentifier testIdentifier = TestIdentifier.from(first.get().getTestDescriptor());
    String uniqueId = testIdentifier.getUniqueId();
    tests = executeTests(selectUniqueId(uniqueId)).testEvents();
    tests.assertStatistics(stats -> stats.started(1).succeeded(1).failed(0));
    first = tests.succeeded().filter(event -> event.getTestDescriptor().getUniqueId().toString().contains(TestInfo.class.getName())).findFirst();
    assertTrue(first.isPresent());
}
Also used : Test(org.junit.jupiter.api.Test) TestIdentifier(org.junit.platform.launcher.TestIdentifier) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) Events(org.junit.platform.testkit.engine.Events) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Event(org.junit.platform.testkit.engine.Event) Optional(java.util.Optional) TestInfo(org.junit.jupiter.api.TestInfo) Events(org.junit.platform.testkit.engine.Events) Event(org.junit.platform.testkit.engine.Event) TestInfo(org.junit.jupiter.api.TestInfo) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 25 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project junit5 by junit-team.

the class VintageLauncherIntegrationTests method execute.

private Map<TestIdentifier, TestExecutionResult> execute(LauncherDiscoveryRequestBuilder requestBuilder) {
    Map<TestIdentifier, TestExecutionResult> results = new LinkedHashMap<>();
    var request = toRequest(requestBuilder);
    var launcher = LauncherFactory.create();
    launcher.execute(request, new TestExecutionListener() {

        @Override
        public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
            results.put(testIdentifier, testExecutionResult);
        }
    });
    return results;
}
Also used : TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TestIdentifier (org.junit.platform.launcher.TestIdentifier)53 Test (org.junit.jupiter.api.Test)29 TestPlan (org.junit.platform.launcher.TestPlan)23 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)17 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)7 LinkedHashMap (java.util.LinkedHashMap)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 Map (java.util.Map)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)5 NumberFormat (java.text.NumberFormat)3 ArrayList (java.util.ArrayList)3 MethodTestDescriptor (org.junit.jupiter.engine.descriptor.MethodTestDescriptor)3 Launcher (org.junit.platform.launcher.Launcher)3