Junit 5 Launcher with jupiter-vintage-engine rule not honoring JUnit4 @ParametrizedTest

574 views Asked by At

I am working on porting a JUnit4 based test framework that uses JUnitCore to launch unit tests with JUnit5 launcher, junit-vintage-engine and a LauncherDiscoveryRequest with ClassSelector.

It is working for all cases except @ParameterizedTest. Launcher is not honoring parameterized tests.

How do I get Launcher to honor JUnit4 parameterized tests?

I have tried adding testCompile("org.junit.jupiter:junit-jupiter-params:${junit_jupiter_version}")

package ...;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import ...TestCategory;
import ...TestType;
import ...DataScramblingRegexTest;

@TestType(...TestCategory.UNIT)
@RunWith(Parameterized.class)
public class RegexGenTest {

    private static final int LOOKAROUND_ATTEMPTS = 100;

    @Parameterized.Parameter(0)
    public String regex;

    @Parameterized.Parameters(name = "{index}: RegexGenTest: {0}")
    public static Iterable<String[]> data() {
        return DataScramblingRegexTest.data();
    }

    @Test
    public void testTransformAndGenerate() {
        //even though Data Scramble Random Text doesn't transform every regex,
        //even if we do, and run it through Generex, it should still work.
        final String transformedRegex = RegexGen.transform(this.regex);
        String randomStr = RegexGen.generate(transformedRegex);
        if (RegexGen.containsLookArounds(this.regex)) {
            for (int i = 0; i < LOOKAROUND_ATTEMPTS; i++) {
                randomStr = RegexGen.generate(transformedRegex);
                if (randomStr.matches(this.regex)) {
                    return;
                }
            }
            Assert.fail("Lookaround failed");
        }
        Assert.assertTrue("generated string does not match regex: " + randomStr, randomStr.matches(this.regex));
    }
}

build.gradle

    compile("junit:junit:${junit_version}")
    testCompile("org.junit.vintage:junit-vintage-engine:${junit_jupiter_version}")
    testCompile("org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}")
    testCompile("org.junit.jupiter:junit-jupiter-params:${junit_jupiter_version}")
    testCompile("org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}")

where

junit_version=4.12
junit_jupiter_version=5.4.2

Note the proprietary TestCategory.UNIT annotation, we use this in our test discovery code and create a Launcher and a LauncherdiscoveryRequest with ClassSelector.

I expect JUnit 4 parameters to be supported by JUnit5 launcher with junit-jupiter-vintage engine and it is not supported.

0

There are 0 answers