use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.
the class MyTestClass method execution.
@org.junit.jupiter.api.Test
void execution() {
// @formatter:off
// tag::execution[]
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example.mytests"), selectClass(MyTestClass.class)).filters(includeClassNamePatterns(".*Tests")).build();
Launcher launcher = LauncherFactory.create();
// Register a listener of your choice
TestExecutionListener listener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request);
// end::execution[]
// @formatter:on
}
use of org.junit.platform.launcher.LauncherDiscoveryRequest 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.LauncherDiscoveryRequest in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesMethodSelectorForTwoMethodsOfSameClass.
@Test
void resolvesMethodSelectorForTwoMethodsOfSameClass() throws Exception {
Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
LauncherDiscoveryRequest discoveryRequest = request().selectors(selectMethod(testClass, testClass.getMethod("failingTest")), selectMethod(testClass, testClass.getMethod("successfulTest"))).build();
TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
assertRunnerTestDescriptor(runnerDescriptor, testClass);
List<TestDescriptor> testMethodDescriptors = new ArrayList<>(runnerDescriptor.getChildren());
assertThat(testMethodDescriptors).hasSize(2);
TestDescriptor failingTest = testMethodDescriptors.get(0);
assertTestMethodDescriptor(failingTest, testClass, "failingTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
TestDescriptor successfulTest = testMethodDescriptors.get(1);
assertTestMethodDescriptor(successfulTest, testClass, "successfulTest", VintageUniqueIdBuilder.uniqueIdForClass(testClass));
}
use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesPackageSelectorForJUnit4SamplesPackage.
@Test
void resolvesPackageSelectorForJUnit4SamplesPackage() {
Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.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(PlainJUnit3TestCaseWithSingleTestWhichFails.class.getName());
// @formatter:on
}
use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesJUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails.
@Test
void resolvesJUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails() throws Exception {
Class<?> suiteClass = JUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails.class;
Class<?> testClass = PlainJUnit3TestCaseWithSingleTestWhichFails.class;
LauncherDiscoveryRequest discoveryRequest = discoveryRequestForClass(suiteClass);
TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
TestDescriptor suiteDescriptor = getOnlyElement(engineDescriptor.getChildren());
assertRunnerTestDescriptor(suiteDescriptor, suiteClass);
TestDescriptor testClassDescriptor = getOnlyElement(suiteDescriptor.getChildren());
assertContainerTestDescriptor(testClassDescriptor, suiteClass, testClass);
TestDescriptor testMethodDescriptor = getOnlyElement(testClassDescriptor.getChildren());
assertTestMethodDescriptor(testMethodDescriptor, testClass, "test", VintageUniqueIdBuilder.uniqueIdForClasses(suiteClass, testClass));
}
Aggregations