diff --git a/as-iwant-developer/i-have/wsdef/src/main/java/org/fluentjava/iwant/wsdef/IwantModules.java b/as-iwant-developer/i-have/wsdef/src/main/java/org/fluentjava/iwant/wsdef/IwantModules.java index 2311d20e..55e67f4c 100644 --- a/as-iwant-developer/i-have/wsdef/src/main/java/org/fluentjava/iwant/wsdef/IwantModules.java +++ b/as-iwant-developer/i-have/wsdef/src/main/java/org/fluentjava/iwant/wsdef/IwantModules.java @@ -108,6 +108,41 @@ private IwantSrcModuleSpex module(String fullName) { "hamcrest-core", "1.3"); private final JavaModule junit = binModule("junit", "junit", "4.13.2", hamcrestCore); + private static final String JUNIT_PLATFORM_VER = "1.10.2"; + private final JavaModule junitPlatformLauncher = binModule( + "org.junit.platform", "junit-platform-launcher", + JUNIT_PLATFORM_VER); + private final JavaModule junitPlatformConsole = binModule( + "org.junit.platform", "junit-platform-console", JUNIT_PLATFORM_VER, + junitPlatformLauncher); + private static final String JUNIT_JUPITER_VER = "5.10.2"; + private final JavaModule junitPlatformCommons = binModule( + "org.junit.platform", "junit-platform-commons", JUNIT_PLATFORM_VER); + private final JavaModule junitPlatformEngine = binModule( + "org.junit.platform", "junit-platform-engine", JUNIT_PLATFORM_VER); + private final JavaModule junitJupiter = binModule("org.junit.jupiter", + "junit-jupiter", JUNIT_JUPITER_VER, junitPlatformCommons, + junitPlatformEngine); + private final JavaModule junitJupiterApi = binModule("org.junit.jupiter", + "junit-jupiter-api", JUNIT_JUPITER_VER); + private final JavaModule junitJupiterEngine = binModule("org.junit.jupiter", + "junit-jupiter-engine", JUNIT_JUPITER_VER); + private final JavaModule junitJupiterParams = binModule("org.junit.jupiter", + "junit-jupiter-params", JUNIT_JUPITER_VER); + private final JavaModule junitVintageEngine = binModule("org.junit.vintage", + "junit-vintage-engine", JUNIT_JUPITER_VER); + private final JavaBinModule opentest4j = binModule("org.opentest4j", + "opentest4j", "1.3.0"); + + private List jupiterCompileDeps() { + return List.of(junit, junitJupiter, junitJupiterApi); + } + + private List jupiterRtDeps() { + return List.of(junitJupiterEngine, junitPlatformCommons, + junitJupiterParams, junitPlatformConsole, junitPlatformEngine, + junitVintageEngine, opentest4j); + } private final JavaBinModule ooxmlNiceXmlMessages = binModule( "com.github.oowekyala.ooxml", "nice-xml-messages", "3.1"); @@ -363,8 +398,10 @@ private static IwantSrcModuleSpex withMockrootMainJavas( .mainDeps(commonsIo, iwantApiAntrunner, iwantApiCore, iwantApiModel, iwantApiJavamodules, iwantApiTarget, iwantApiZip, iwantCoreAnt, iwantCoreDownload, iwantEntry, iwantEntry3, - iwantPluginAnt) - .testDeps(junit, iwantApimocks, iwantEmbedded, iwantTestarea).end(); + iwantPluginAnt, junitPlatformConsole) + .mainDeps(jupiterCompileDeps()) + .testDeps(iwantApimocks, iwantEmbedded, iwantTestarea) + .testRuntimeDeps(jupiterRtDeps()).end(); // TODO don't depend directly on asm, jaxen, ...: pmd depends on them private JavaSrcModule iwantPluginPmd = optionalModule("plugin-pmd") diff --git a/optional/iwant-plugin-jacoco/src/main/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModules.java b/optional/iwant-plugin-jacoco/src/main/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModules.java index da646e1a..b906d4b1 100644 --- a/optional/iwant-plugin-jacoco/src/main/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModules.java +++ b/optional/iwant-plugin-jacoco/src/main/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModules.java @@ -139,7 +139,7 @@ private static String testRunnerClassNameFor(JavaSrcModule mod) { if (mod.testRunner() != null) { return mod.testRunner().mainClassName(); } - return "org.junit.runner.JUnitCore"; + return "org.fluentjava.iwant.plugin.jacoco.Junit5Runner"; } private void dep(JacocoCoverageSpexPlease coverage, JavaModule mod) { diff --git a/optional/iwant-plugin-jacoco/src/main/java/org/fluentjava/iwant/plugin/jacoco/Junit5Runner.java b/optional/iwant-plugin-jacoco/src/main/java/org/fluentjava/iwant/plugin/jacoco/Junit5Runner.java new file mode 100644 index 00000000..d0d77bc3 --- /dev/null +++ b/optional/iwant-plugin-jacoco/src/main/java/org/fluentjava/iwant/plugin/jacoco/Junit5Runner.java @@ -0,0 +1,38 @@ +package org.fluentjava.iwant.plugin.jacoco; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.fluentjava.iwant.entry.Iwant; +import org.junit.platform.console.ConsoleLauncher; + +public class Junit5Runner { + + public static void main(String[] args) { + Iwant.debugLog(Junit5Runner.class.getCanonicalName(), + Arrays.toString(args)); + List runnerArgs = new ArrayList<>(); + + for (String arg : args) { + runnerArgs.add("-c"); + runnerArgs.add(arg); + } + if (runnerArgs.isEmpty()) { + Iwant.debugLog(Junit5Runner.class.getCanonicalName(), + "No tests given, exiting."); + return; + } + + int exitCode = 1; + try (PrintWriter out = new PrintWriter(System.out); + PrintWriter err = new PrintWriter(System.err)) { + exitCode = ConsoleLauncher + .run(out, err, runnerArgs.toArray(new String[0])) + .getExitCode(); + } finally { + System.exit(exitCode); + } + } +} diff --git a/optional/iwant-plugin-jacoco/src/test/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModulesTest.java b/optional/iwant-plugin-jacoco/src/test/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModulesTest.java index 4ea197dd..4f43a50d 100644 --- a/optional/iwant-plugin-jacoco/src/test/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModulesTest.java +++ b/optional/iwant-plugin-jacoco/src/test/java/org/fluentjava/iwant/plugin/jacoco/JacocoTargetsOfJavaModulesTest.java @@ -87,10 +87,10 @@ public void testTargetsFromOneMinimalTestOnlyModule() { + "i:jacoco:\n" + " jacoco-0.8.10\n" + "i:antJars:\n" + " " + antJar() + "\n " + antLauncherJar() + "\ni:classLocations:\n" + " mod-test-classes\n" + "p:mainClassName:\n" - + " org.junit.runner.JUnitCore\n" + "p:mainClassArgs:\n" - + " null-collection\n" + "i:mainClassArgsFile:\n" - + " mod-test-class-names\n" + "p:jvmargs:\n", - coverage.contentDescriptor()); + + " org.fluentjava.iwant.plugin.jacoco.Junit5Runner\n" + + "p:mainClassArgs:\n" + " null-collection\n" + + "i:mainClassArgsFile:\n" + " mod-test-class-names\n" + + "p:jvmargs:\n", coverage.contentDescriptor()); JacocoReport report = jacocoTargets.jacocoReport("report"); assertEquals("org.fluentjava.iwant.plugin.jacoco.JacocoReport\n" @@ -145,7 +145,7 @@ public String toString() { JacocoCoverage coverageOfOneClass = jacocoTargets .jacocoCoverageOf(testedByOneClass); - assertEquals("org.junit.runner.JUnitCore", + assertEquals("org.fluentjava.iwant.plugin.jacoco.Junit5Runner", coverageOfOneClass.mainClassName()); assertEquals("[custom.Test]", coverageOfOneClass.mainClassArgs().toString()); @@ -153,7 +153,7 @@ public String toString() { JacocoCoverage coverageOfManyClasses = jacocoTargets .jacocoCoverageOf(testedByClassnameFilter); - assertEquals("org.junit.runner.JUnitCore", + assertEquals("org.fluentjava.iwant.plugin.jacoco.Junit5Runner", coverageOfManyClasses.mainClassName()); assertNull(coverageOfManyClasses.mainClassArgs()); ClassNameList testNames = (ClassNameList) coverageOfManyClasses @@ -263,7 +263,7 @@ public void testJacocoCoverageUsesModulesTestEnv() { assertSame(env, coverage.env()); } - public void testJunitRunnerIsUsedForCoverageByDefault() { + public void testOwnJunitRunnerIsUsedForCoverageByDefault() { JavaSrcModule mod = JavaSrcModule.with().name("mod").testJava("test") .end(); @@ -272,7 +272,8 @@ public void testJunitRunnerIsUsedForCoverageByDefault() { .modules(mod).end(); JacocoCoverage coverage = jacocoTargets.jacocoCoverageOf(mod); - assertEquals("org.junit.runner.JUnitCore", coverage.mainClassName()); + assertEquals("org.fluentjava.iwant.plugin.jacoco.Junit5Runner", + coverage.mainClassName()); } public void testCustomTestRunnerIsUsedForCoverage() {