use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class JUnitPlatform method generateTestTree.
private JUnitPlatformTestTree generateTestTree() {
Preconditions.notNull(this.discoveryRequest, "DiscoveryRequest must not be null");
TestPlan plan = this.launcher.discover(this.discoveryRequest);
return new JUnitPlatformTestTree(plan, testClass);
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class MyTestClass method discovery.
@org.junit.jupiter.api.Test
@SuppressWarnings("unused")
void discovery() {
// @formatter:off
// tag::discovery[]
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example.mytests"), selectClass(MyTestClass.class)).filters(includeClassNamePatterns(".*Tests")).build();
Launcher launcher = LauncherFactory.create();
TestPlan testPlan = launcher.discover(request);
// end::discovery[]
// @formatter:on
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class VintageLauncherIntegrationTests method executesIncludedTaggedMethodOfNestedTestClass.
@Test
void executesIncludedTaggedMethodOfNestedTestClass() {
Class<?> testClass = EnclosedJUnit4TestCase.class;
Class<?> nestedTestClass = EnclosedJUnit4TestCase.NestedClass.class;
LauncherDiscoveryRequestBuilder request = //
request().selectors(//
selectClass(testClass)).filters(includeTags(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(), "failingTest");
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class VintageLauncherIntegrationTests method removesWholeSubtree.
@Test
void removesWholeSubtree() {
Class<?> testClass = EnclosedJUnit4TestCase.class;
LauncherDiscoveryRequestBuilder request = //
request().selectors(//
selectClass(testClass)).filters(excludeTags(Categories.Plain.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)).containsExactlyInAnyOrder("JUnit Vintage");
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class VintageLauncherIntegrationTests method executesAllTestsForNotFilterableChildRunnerOfSuite.
@TrackLogRecords
@Test
void executesAllTestsForNotFilterableChildRunnerOfSuite(LogRecordListener logRecordListener) {
Class<?> suiteClass = JUnit4SuiteOfSuiteWithFilterableChildRunner.class;
Class<?> testClass = JUnit4TestCaseWithNotFilterableRunner.class;
LauncherDiscoveryRequestBuilder request = //
request().selectors(//
selectClass(suiteClass)).filters((PostDiscoveryFilter) descriptor -> includedIf(descriptor.getDisplayName().contains("#1")));
TestPlan testPlan = discover(request);
logRecordListener.clear();
assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).hasSize(4);
Map<TestIdentifier, TestExecutionResult> results = execute(request);
//
assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage", suiteClass.getName(), testClass.getName(), "Test #0", "Test #1");
//
assertThat(logRecordListener.stream(RunnerTestDescriptor.class, Level.WARNING).map(LogRecord::getMessage)).containsExactly(//
"Runner " + Suite.class.getName() + " (used on class " + suiteClass.getName() + ")" + " was not able to satisfy all filter requests.");
}
Aggregations