Skip to content

Methods in parameterized classes should be part of the test plan #4649

Closed as not planned
@LeggoMahEggo

Description

@LeggoMahEggo

In the JUnit 5.13 update, the ParameterizedClass annotation was released, and it is perfect for certain sets of tests that I need to write for my company's tools. It works fine when executing the test class directly via IntelliJ, but when I went to my test information code to see if additional support was needed, I found that those tests weren't being discovered. I hope that this can be fixed soon; I've already written several test classes with ParameterizedClass in mind, and am looking to run them for our next release.

Steps to reproduce

Code

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedClass;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.platform.engine.DiscoverySelector;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TestIdentifier;
import org.junit.platform.launcher.TestPlan;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;

import java.util.List;
import java.util.Set;

public class ParameterizedClassTestDiscovery {

    // Without parameterized class annotation
    static class TestClassA {
        @Test
        public void test1() {
        }

        @Test
        public void test2() {
        }
    }

    // With parameterized class annotation
    @ParameterizedClass
    @ValueSource(ints = 1)
    static class TestClassB {
        @Parameter
        int intValue;

        @Test
        public void test1() {
        }

        @Test
        public void test2() {
        }
    }

    public static void main(String[] args) {
        List<Class<?>> classesToTest = List.of(TestClassA.class, TestClassB.class);

        for (Class<?> clazz : classesToTest) {
            System.out.println("=== " + clazz.getSimpleName() + " ===");
            DiscoverySelector selector = DiscoverySelectors.selectClass(clazz);
            LauncherDiscoveryRequest testsFound = LauncherDiscoveryRequestBuilder.request().selectors(selector).build();
            TestPlan plan = LauncherFactory.create().discover(testsFound);

            for (TestIdentifier identifier : plan.getRoots()) {
                Set<TestIdentifier> descendants = plan.getDescendants(identifier);
                descendants.forEach(descendant -> System.out.printf("%s: %s\n", descendant.getDisplayName(), descendant.isTest()));
            }
            System.out.println();
        }
    }
}

Expected output:

=== TestClassA ===
ParameterizedClassTestDiscovery$TestClassA: false
test1(): true
test2(): true

=== TestClassB ===
ParameterizedClassTestDiscovery$TestClassB: false
test1(): true
test2(): true

Actual output:

=== TestClassA ===
ParameterizedClassTestDiscovery$TestClassA: false
test1(): true
test2(): true

=== TestClassB ===
ParameterizedClassTestDiscovery$TestClassB: false

Context

  • Used versions (Jupiter/Vintage/Platform): JUnit Jupiter v5.13.1, JUnit Platform 1.13.0
  • Build Tool/IDE: Maven, IntelliJ

Deliverables

  • ...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions