JUnit 5 控制台启动器在 JAR 中找不到测试
JUnit 5 console launcher does not find tests inside JAR
我有一个包含测试 classes 和所有依赖项的阴影 uber JAR。但是 JUnit 5 控制台启动器找不到任何测试:
java -jar junit-platform-console-standalone.jar --scan-classpath=/path/to/test-suite-all.jar
╷
├─ JUnit Jupiter ✔
└─ JUnit Vintage ✔
Test run finished after 33 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
测试 class 名称以 Test
结尾,匹配默认的 --include-classname
正则表达式。
我应该期望它起作用吗?我做错了什么?
这些尝试也以同样的方式失败:
java -jar junit-platform-console-standalone.jar --scan-classpath -cp=/path/to/test-suite-all.jar
java -cp junit-platform-console-standalone.jar:/path/to/test-suite-all.jar org.junit.platform.console.ConsoleLauncher --scan-classpath
更新
Minimal example repository, run with ./gradlew junitConsoleLauncher
. This repo now works correctly thanks to johanneslink的建议。
克隆您的存储库并将存储库添加到构建文件后,以下对我有用:
gradle wrapper
./gradlew shadowJar
java -cp ./build/libs/junit-console-launcher-shaded-jar-all.jar org.junit.platform.console.ConsoleLauncher --scan-classpath ./build/libs/junit-console-launcher-shaded-jar-all.jar
输出:
╷
└─ JUnit Jupiter ✔
└─ ExampleTest ✔
└─ test() ✔
Test run finished after 50 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
使用 -jar
选项不起作用,可能是因为 shadow jar 中的清单设置不正确。
我有一个包含测试 classes 和所有依赖项的阴影 uber JAR。但是 JUnit 5 控制台启动器找不到任何测试:
java -jar junit-platform-console-standalone.jar --scan-classpath=/path/to/test-suite-all.jar
╷
├─ JUnit Jupiter ✔
└─ JUnit Vintage ✔
Test run finished after 33 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
测试 class 名称以 Test
结尾,匹配默认的 --include-classname
正则表达式。
我应该期望它起作用吗?我做错了什么?
这些尝试也以同样的方式失败:
java -jar junit-platform-console-standalone.jar --scan-classpath -cp=/path/to/test-suite-all.jar
java -cp junit-platform-console-standalone.jar:/path/to/test-suite-all.jar org.junit.platform.console.ConsoleLauncher --scan-classpath
更新
Minimal example repository, run with ./gradlew junitConsoleLauncher
. This repo now works correctly thanks to johanneslink的建议。
克隆您的存储库并将存储库添加到构建文件后,以下对我有用:
gradle wrapper
./gradlew shadowJar
java -cp ./build/libs/junit-console-launcher-shaded-jar-all.jar org.junit.platform.console.ConsoleLauncher --scan-classpath ./build/libs/junit-console-launcher-shaded-jar-all.jar
输出:
╷
└─ JUnit Jupiter ✔
└─ ExampleTest ✔
└─ test() ✔
Test run finished after 50 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
使用 -jar
选项不起作用,可能是因为 shadow jar 中的清单设置不正确。