Gradle Junit测试报错No tests found for given includes:[XXX](filter.includeTestsMatching)

Testing started at 15:27 ...
> Task :cleanTest
> Task :compileKotlin NO-SOURCE
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestKotlin
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [App.checkDirExist](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5s
3 actionable tasks: 3 executed

解决方向分两种

Gradle 问题

检查build.gradle 包含下面语句

test {
    useJUnitPlatform()
}

JUnit代码 问题

检查测试代码是不是不规范

@Test
fun checkDirExist(): Boolean {
   File(BASE_PATH.plus("/newFolder")).run {
     return exists() && isDirectory
   }
}

上面的写法肯定会报这个错
因为
JUnit测试不能返回任何值

你可能感兴趣的:(问题集)