我正在努力移植基于JUnit4的测试框架,该框架使用JUnitCore来通过JUnit5启动器,junit-vintage-engine和带有ClassSelector的LauncherDiscoveryRequest启动单元测试。
它适用于除@ParameterizedTest之外的所有情况。启动器不接受参数化测试。
如何让Launcher兑现JUnit4参数化测试?
我尝试添加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}")
其中
junit_version=4.12
junit_jupiter_version=5.4.2
请注意专有的TestCategory.UNIT
批注,我们在测试发现代码中使用了它,并使用Launcher
创建了LauncherdiscoveryRequest
和ClassSelector
。
我希望具有junit-jupiter-vintage引擎的JUnit5启动器支持JUnit 4参数,并且不支持该参数。