use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder in project intellij-community by JetBrains.
the class JUnit5TestRunnerUtil method buildRequest.
public static LauncherDiscoveryRequest buildRequest(String[] suiteClassNames, String[] packageNameRef) {
if (suiteClassNames.length == 0) {
return null;
}
LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request();
if (suiteClassNames.length == 1 && suiteClassNames[0].charAt(0) == '@') {
// all tests in the package specified
try {
BufferedReader reader = new BufferedReader(new FileReader(suiteClassNames[0].substring(1)));
try {
final String packageName = reader.readLine();
if (packageName == null)
return null;
String tagName = reader.readLine();
String line;
List<DiscoverySelector> selectors = new ArrayList<>();
while ((line = reader.readLine()) != null) {
selectors.add(createSelector(line));
}
packageNameRef[0] = packageName.length() == 0 ? "<default package>" : packageName;
builder = selectors.isEmpty() ? builder.selectors(DiscoverySelectors.selectPackage(packageName)) : builder.selectors(selectors);
if (tagName != null && !tagName.isEmpty()) {
builder = builder.filters(TagFilter.includeTags(tagName));
}
return builder.build();
} finally {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
} else {
boolean disableDisabledCondition = isDisabledConditionDisabled(suiteClassNames[0]);
if (disableDisabledCondition) {
builder = builder.configurationParameter("junit.conditions.deactivate", "org.junit.*DisabledCondition");
}
return builder.selectors(createSelector(suiteClassNames[0])).build();
}
return null;
}
use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder in project junit5 by junit-team.
the class DiscoveryRequestCreator method toDiscoveryRequest.
LauncherDiscoveryRequest toDiscoveryRequest(CommandLineOptions options) {
LauncherDiscoveryRequestBuilder requestBuilder = request();
requestBuilder.selectors(createDiscoverySelectors(options));
addFilters(requestBuilder, options);
requestBuilder.configurationParameters(options.getConfigurationParameters());
return requestBuilder.build();
}
use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder in project junit5 by junit-team.
the class JUnitPlatform method createDiscoveryRequest.
private LauncherDiscoveryRequest createDiscoveryRequest() {
List<DiscoverySelector> selectors = getSelectorsFromAnnotations();
// Allows to simply add @RunWith(JUnitPlatform.class) to any test case
boolean isSuite = !selectors.isEmpty();
if (!isSuite) {
selectors.add(selectClass(this.testClass));
}
LauncherDiscoveryRequestBuilder requestBuilder = request().selectors(selectors);
addFiltersFromAnnotations(requestBuilder, isSuite);
return requestBuilder.build();
}
use of org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder 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.core.LauncherDiscoveryRequestBuilder 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");
}
Aggregations