Search in sources :

Example 21 with TestPlan

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

the class VintageLauncherIntegrationTests method filtersOutAllDescendantsOfParameterizedTestCase.

@Test
void filtersOutAllDescendantsOfParameterizedTestCase() {
    Class<?> testClass = ParameterizedTestCase.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters((PostDiscoveryFilter) descriptor -> excluded("excluded"));
    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 : 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) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) TestPlan(org.junit.platform.launcher.TestPlan) ParameterizedTestCase(org.junit.vintage.engine.samples.junit4.ParameterizedTestCase) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 22 with TestPlan

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

the class VintageLauncherIntegrationTests method executesOnlyTaggedMethodOfRegularTestClass.

@Test
void executesOnlyTaggedMethodOfRegularTestClass() {
    Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters(includeTags(Categories.Failing.class.getName()));
    TestPlan testPlan = discover(request);
    assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).hasSize(2);
    Map<TestIdentifier, TestExecutionResult> results = execute(request);
    // 
    assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage", testClass.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) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 23 with TestPlan

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

the class VintageLauncherIntegrationTests method executesOnlyTaggedMethodsForSuite.

@Test
void executesOnlyTaggedMethodsForSuite() {
    Class<?> suiteClass = JUnit4SuiteWithTwoTestCases.class;
    Class<?> testClass = PlainJUnit4TestCaseWithTwoTestMethods.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(suiteClass)).filters(includeTags(Categories.Successful.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", suiteClass.getName(), testClass.getName(), "successfulTest");
}
Also used : PlainJUnit4TestCaseWithTwoTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods) 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) JUnit4SuiteWithTwoTestCases(org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithTwoTestCases) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 24 with TestPlan

use of org.junit.platform.launcher.TestPlan 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 25 with TestPlan

use of org.junit.platform.launcher.TestPlan in project tutorials by eugenp.

the class TestLauncher method main.

public static void main(String[] args) {
    // @formatter:off
    LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectClass("com.baeldung.EmployeesTest")).configurationParameter("junit.conditions.deactivate", "com.baeldung.extensions.*").configurationParameter("junit.extensions.autodetection.enabled", "true").build();
    // @formatter:on
    TestPlan plan = LauncherFactory.create().discover(request);
    Launcher launcher = LauncherFactory.create();
    SummaryGeneratingListener summaryGeneratingListener = new SummaryGeneratingListener();
    launcher.execute(request, new TestExecutionListener[] { summaryGeneratingListener });
    launcher.execute(request);
    summaryGeneratingListener.getSummary().printTo(new PrintWriter(System.out));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestPlan(org.junit.platform.launcher.TestPlan) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) Launcher(org.junit.platform.launcher.Launcher) PrintWriter(java.io.PrintWriter)

Aggregations

TestPlan (org.junit.platform.launcher.TestPlan)47 Test (org.junit.jupiter.api.Test)38 TestIdentifier (org.junit.platform.launcher.TestIdentifier)24 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)16 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)16 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)10 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)9 UniqueId (org.junit.platform.engine.UniqueId)8 Launcher (org.junit.platform.launcher.Launcher)8 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 TestDescriptor (org.junit.platform.engine.TestDescriptor)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)4 TestEngine (org.junit.platform.engine.TestEngine)4 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)4