org.junit.platform.engine.discovery.ClassSelector Java Examples

The following examples show how to use org.junit.platform.engine.discovery.ClassSelector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EngineDiscoveryTestRequest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked") // compatibility is explicitly checked
public <T extends DiscoverySelector> List<T> getSelectorsByType(Class<T> selectorType) {
    if (ClasspathRootSelector.class.equals(selectorType)) {
        return (List<T>) createClasspathRootSelectors(classpathRootsToDiscover);
    }
    if (PackageSelector.class.equals(selectorType)) {
        return (List<T>) createPackageSelectors(packagesToDiscover);
    }
    if (ClassSelector.class.equals(selectorType)) {
        return (List<T>) createClassSelectors(classesToDiscover);
    }
    if (MethodSelector.class.equals(selectorType)) {
        return (List<T>) createMethodSelectors(methodsToDiscover);
    }
    if (FieldSelector.class.equals(selectorType)) {
        return (List<T>) createFieldSelectors(fieldsToDiscover);
    }
    if (UniqueIdSelector.class.equals(selectorType)) {
        return (List<T>) createUniqueIdSelectors(idsToDiscover);
    }
    return emptyList();
}
 
Example #2
Source File: AllureJunit5Test.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Step("Run classes {classes}")
private AllureResults runClasses(final Class<?>... classes) {
    final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);

    final ClassSelector[] classSelectors = Stream.of(classes)
            .map(DiscoverySelectors::selectClass)
            .toArray(ClassSelector[]::new);

    final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .configurationParameter("junit.jupiter.extensions.autodetection.enabled", "true")
            .selectors(classSelectors)
            .build();

    final LauncherConfig config = LauncherConfig.builder()
            .enableTestExecutionListenerAutoRegistration(false)
            .addTestExecutionListeners(new AllureJunitPlatform(lifecycle))
            .build();
    final Launcher launcher = LauncherFactory.create(config);

    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        launcher.execute(request);
        return writerStub;
    } finally {
        Allure.setLifecycle(defaultLifecycle);
        StepsAspects.setLifecycle(defaultLifecycle);
        AttachmentsAspects.setLifecycle(defaultLifecycle);
    }
}
 
Example #3
Source File: AllureJunitPlatformTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Step("Run classes {classes}")
private AllureResults runClasses(final Class<?>... classes) {
    final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);

    final ClassSelector[] classSelectors = Stream.of(classes)
            .map(DiscoverySelectors::selectClass)
            .toArray(ClassSelector[]::new);

    final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .selectors(classSelectors)
            .build();

    final LauncherConfig config = LauncherConfig.builder()
            .enableTestExecutionListenerAutoRegistration(false)
            .addTestExecutionListeners(new AllureJunitPlatform(lifecycle))
            .build();
    final Launcher launcher = LauncherFactory.create(config);

    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        launcher.execute(request);
        return writerStub;
    } finally {
        Allure.setLifecycle(defaultLifecycle);
        StepsAspects.setLifecycle(defaultLifecycle);
        AttachmentsAspects.setLifecycle(defaultLifecycle);
    }
}
 
Example #4
Source File: ArchUnitTestEngine.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private void resolveRequestedClasses(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId, ArchUnitEngineDescriptor result) {
    discoveryRequest.getSelectorsByType(ClassSelector.class).stream()
            .map(ClassSelector::getJavaClass)
            .filter(this::isArchUnitTestCandidate)
            .forEach(clazz -> ArchUnitTestDescriptor.resolve(
                    result, ElementResolver.create(result, uniqueId, clazz), cache.get()));
}
 
Example #5
Source File: TestClassExecutor.java    From webtester2-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T extends DiscoverySelector> List<T> getSelectorsByType(Class<T> selectorType) {
    if (ClassSelector.class.equals(selectorType)) {
        List<T> list = new ArrayList<>();
        list.add(( T ) DiscoverySelectors.selectClass(testClass));
        return list;
    }
    return Collections.emptyList();
}
 
Example #6
Source File: EngineDiscoveryTestRequest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private List<ClassSelector> createClassSelectors(List<Class<?>> classesToDiscover) {
    return classesToDiscover.stream().map(DiscoverySelectors::selectClass).collect(toList());
}