如何 运行 仅使用 Gradle 和 JUnit 5 进行特定测试?
How to run only specific tests with Gradle and JUnit 5?
使用 Gradle 及其 JUnit 4 支持,我可以使用 --tests
选项选择特定测试,如下所示:
$ ./gradlew test --tests de.mp.BarMT
此选项在使用 JUnit 5 Gradle 任务时无效。从命令行使用 test
任务时,它会被静默忽略。无论如何,真正的工作是由 junitPlatformTest
完成的,它不支持选项:
$ ./gradlew clean junitPlatformTest --tests de.mp.BarMT
…
Problem configuring task :junitPlatformTest from command line.
> Unknown command-line option '--tests'.
JUnit 5 插件是否支持选择特定测试?
回答我自己...很多时间过去了,新版本来了,我可以确认 Gradle 5.4.1 和 JUnit Jupiter Platform 1.4.2,简单的配置:
test {
useJUnitPlatform()
}
将允许 运行 单个测试,如 中所示,即使使用奇怪的名称(来自 Kotlin)也是如此:
gradle test --tests 'HtmlForwardInterceptorTest.should forward requests'
使用 Gradle 及其 JUnit 4 支持,我可以使用 --tests
选项选择特定测试,如下所示:
$ ./gradlew test --tests de.mp.BarMT
此选项在使用 JUnit 5 Gradle 任务时无效。从命令行使用 test
任务时,它会被静默忽略。无论如何,真正的工作是由 junitPlatformTest
完成的,它不支持选项:
$ ./gradlew clean junitPlatformTest --tests de.mp.BarMT
…
Problem configuring task :junitPlatformTest from command line.
> Unknown command-line option '--tests'.
JUnit 5 插件是否支持选择特定测试?
回答我自己...很多时间过去了,新版本来了,我可以确认 Gradle 5.4.1 和 JUnit Jupiter Platform 1.4.2,简单的配置:
test {
useJUnitPlatform()
}
将允许 运行 单个测试,如 中所示,即使使用奇怪的名称(来自 Kotlin)也是如此:
gradle test --tests 'HtmlForwardInterceptorTest.should forward requests'