Junit测试Gradle项目时报错:No tests found for given includes: [xxxx.xxxxTest](filter.includeTestsMatching)

背景&错误提示

使用IDEA给旧Gradle项目编写Junit5单元测试时,发现执行测试方法时,控制台报错:

Execution failed for task ':test'.

> No tests found for given includes: [com.github.cuteluobo.service.Impl.YysRollServiceImplTest](filter.includeTestsMatching)

错误图例

问题解决

解决方案A(推荐,Junit5) :修改build.gradle / build.gradle.kts

详细可看gradle官方文档:Using JUnit 5
在build.gradle文件中,增加以下代码:

test {
    useJUnitPlatform()
}

或,在build.gradle.kts文件中,增加以下代码:

tasks.named<Test>("test") {
    useJUnitPlatform()
}
解决方案B(Junit4/5):修改IDEA中的build设置,使用IDEA运行测试

路径:Settings -> Build,Execution,Deployment -> Build Tools -> Gradle
Junit测试Gradle项目时报错:No tests found for given includes: [xxxx.xxxxTest](filter.includeTestsMatching)_第1张图片

延伸阅读

  • stackoverflow中相关问题讨论:https://stackoverflow.com/questions/30474767/no-tests-found-for-given-includes-error-when-running-parameterized-unit-test-in

你可能感兴趣的:(摸鱼抽卡插件,gradle,junit,intellij-idea)