No tests found for given includes
Here is 3 ways it can happen and how to fix.
check that your build.gradle has a test configuration block calling the useJUnitPlatform
JUnit5 separates the API of testing from the implementation.
If you are using Kotlin for your build, make sure your build.gradle.kts contains
tasks.test {
useJUnitPlatform()
}
Another way No tests for given includes can come up is if you are missing the JUnit engine dependency. Make sure your build.gradle has
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
in the dependencies block.
It doesn't have to be 5.6.2 -- just any 5 version.
You can also use testCompile or testImplementation.
but testRuntimeOnly is the most appropriate because it restricts the dependency to its needed use.
If you are using Kotlin, make sure your build.gradle.kts dependencies block contains:
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2")
The problem of not specifying the engine dependency probably happens when developers do not realize JUnit 5 separates the API from the engine. It is possible to use the JUnit 5 API without using the JUnit 5 engine; you could use a 3rd party engine. Maybe you took the top hit on mvnrepository, but notice there is also the engine with nearly as many hits. You need both.
A related problem to No tests for given includes is that your tests may not be recognized by your IDE such as IDEA. They also are not recognized when invoking the tests through gradlew. You are using the wrapper, right? So your IDE doesn't offer the green triangle to run individual tests. And if you execute the test task, it completes successfully, but no tests were run.
This often happens when you change from JUnit 4 to JUnit 5. JUnit 5 is backwards compatible with JUnit 4. So there is a Test annotation at its original full class name of org.junit.Test. Your test annotation should come from org.junit.jupiter.api.Test. Note that the code will compile with the JUnit 4 class name -- it just won't run the tests. Change that import.
Ещё видео!