我在同一个gradle项目(Jenkins插件)中使用JUnit 4.13.1和TestNg 6.14.3。一个类有TestNg单元测试,另一个有JUnit单元测试。对我来说,这两个类不能一起工作。如果我在build.gradle
中使用此配置,则只有JUnit可以工作
test {
testLogging {
showStandardStreams = true
}
doFirst {
environment 'OUTPUT_DIR', project.buildDir
systemProperty 'build.notifications.disabled', 'true'
}
useTestNG()
useJUnit()
}
如果我使用下面的配置或删除useJUnit(),那么只有JUnit工作。
test {
testLogging {
showStandardStreams = true
}
doFirst {
environment 'OUTPUT_DIR', project.buildDir
systemProperty 'build.notifications.disabled', 'true'
}
useJUnit()
}
如果我只保留useTestNG(),那么只有TestNG可以工作。在同一个gradle项目中运行这两个函数的正确配置是什么?
Execution failed for task ':test'.
> No tests found for given includes: [com.build.plugins.TestDataTest](--tests filter)
1条答案
按热度按时间4c8rllxm1#
在概念上,这样写是错误的
因为一个测试只能使用一个测试框架。因此在这种情况下,JUnit会覆盖TestNG。
JUnit 5是此案例的解决方案。
为什么?
JUnit平台是在JVM上启动测试框架的基础,它还定义了用于开发在平台上运行的测试框架的TestEngine API
以及
怎么做?
将
build.gradle
设置为有用资源:JUnit 5第三方扩展Gradle Testing in Java & JVM projects