use of org.junit.platform.engine.DiscoverySelector 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.engine.DiscoverySelector 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.engine.DiscoverySelector in project cucumber-jvm by cucumber.
the class DiscoverySelectorResolverTest method resolveRequestWithClasspathResourceSelectorAndFilePosition.
@Test
void resolveRequestWithClasspathResourceSelectorAndFilePosition() {
String feature = "io/cucumber/junit/platform/engine/rule.feature";
FilePosition line = FilePosition.from(5);
DiscoverySelector resource = selectClasspathResource(feature, line);
EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
resolver.resolveSelectors(discoveryRequest, testDescriptor);
assertEquals(1L, testDescriptor.getDescendants().stream().filter(TestDescriptor::isTest).count());
}
use of org.junit.platform.engine.DiscoverySelector in project cucumber-jvm by cucumber.
the class DiscoverySelectorResolverTest method resolveRequestWithMultipleClasspathResourceSelector.
@Test
void resolveRequestWithMultipleClasspathResourceSelector() {
DiscoverySelector resource1 = selectClasspathResource("io/cucumber/junit/platform/engine/single.feature");
DiscoverySelector resource2 = selectClasspathResource("io/cucumber/junit/platform/engine/feature-with-outline.feature");
EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource1, resource2);
resolver.resolveSelectors(discoveryRequest, testDescriptor);
assertEquals(2, testDescriptor.getChildren().size());
}
use of org.junit.platform.engine.DiscoverySelector in project cucumber-jvm by cucumber.
the class DiscoverySelectorResolverTest method resolveRequestWithUniqueIdSelectorFromFileUri.
@Test
void resolveRequestWithUniqueIdSelectorFromFileUri() {
DiscoverySelector resource = selectDirectory("src/test/resources/io/cucumber/junit/platform/engine");
EngineDiscoveryRequest discoveryRequest = new SelectorRequest(resource);
resolver.resolveSelectors(discoveryRequest, testDescriptor);
Set<? extends TestDescriptor> descendants = testDescriptor.getDescendants();
descendants.forEach(targetDescriptor -> {
resetTestDescriptor();
resolveRequestWithUniqueIdSelector(targetDescriptor.getUniqueId());
assertEquals(1, testDescriptor.getChildren().size());
assertThat(testDescriptor, allDescriptorsPrefixedBy(targetDescriptor.getUniqueId()));
});
}
Aggregations