"No tests found for given includes" when running Gradle tests in IntelliJ IDEA
Solution 1
Thanks to Ben Watson I've found solution. Since JUnit 5.4.0 there is aggregate artifact with both api and engine dependencies. So just adding one dependency to build.gradle resolved this issue.
testCompile ('org.junit.jupiter:junit-jupiter:5.6.0')
Solution 2
I had this error with a similar setup, but couldn't solve it with the previous answers. Resolved it by doing this.
- File > Setting (Ctrl+Alt+S)
- Build, Execution, Deployment > Build Tools > gradle
- Run Tests using: Intellij IDEA
All credit to: https://linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/.
Solution 3
Gradle has no idea where to look for tests. Add this to your app build.gradle file root(Not inside android or dependencies closure):
tasks.withType(Test) {
useJUnitPlatform()
testLogging { // This is for logging and can be removed.
events("passed", "skipped", "failed")
}
}
Solution 4
Another cause of this behaviour when using IntelliJ to edit a Kotlin project is the folders used for the tests, Java classes need to be in a subfolder of java and Kotlin classes in a subfolder of kotlin.
Here's an example of a mini-project I created which demonstrates the folder structure https://github.com/znsio/AutomatedTestingWithKotlin/tree/main/src/test
I found the explanation which is quoted below together with the link to the source:
"My problem was in single path to kotlin and java tests. So kotlin tests are in root/src/test/kotlin/package
and they are running fine with gradle :cleanTest :test
and java tests must be in root/src/test/java/package
. Otherwise neither compileTestKotlin
nor compileTestJava
will not find java tests to compile."
https://discuss.kotlinlang.org/t/not-able-to-run-unit-tests-on-kotlin-multiplatform-project/15779/7
Solution 5
Gradle is case sensitive in choosing its selector. See here You may need to change "GradleTests" to "gradleTests"
Related videos on Youtube
Arrovil
Updated on March 23, 2022Comments
-
Arrovil about 2 years
I cannot run tests via Gradle in IntelliJ IDEA because of "No tests found for given includes" error.
How can I fix it?
GradleTests
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class GradleTests { @Test public void initTest() { assertTrue(true); } }
build.gradle
plugins { id 'java' } group 'org.example' version '1.0-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { //testCompile group: 'junit', name: 'junit', version: '4.12' // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0' } test { useJUnitPlatform() }
Error:
> Task :test FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':test'. > No tests found for given includes: [GradleTests.initTest](filter.includeTestsMatching)
Some notes:
- Issue is reproduced with both JUnit 4 and 5
- IntelliJ IDEA 2019.3.3 (Community Edition), Build #IC-193.6494.35, built on February 11, 2020
- Test is in
src/test/java
- changing runner like Intelij 2019.1 update breaks JUnit tests didn't help
- without
useJUnitPlatform()
result is the same
-
Ben Watson over 4 yearsWhat's your Gradle version, and can you run the test from the command line?
-
Ben Watson over 4 yearsAnd have you tried adding
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0")
-
Arrovil over 4 years@BenWatson thanks for help! I read more about JUnit5 last versions and find out that from 5.4.0 it has aggregated artifact "junit-jupiter" (it is more suitable for me) which included both api and engine. It seems that "engine" has been loaded from some other dependency in my main project.
-
johanneslink over 4 yearsSo does it work with the aggregate artefact?
-
Arrovil about 4 years@johanneslink Yes, I can run my tests with aggregate artifact. I've added and accepted answer to this question.
-
Girish almost 3 years@BenWatson I am using Junit 4.13.1, how to resolve this
-
Georgi about 4 yearsStrangely, your solution didn't work for me and I have quite similar setup to yours. As a work-around I created manually a JUnit IntelliJ configuration ... but is not cool :/
-
Calabacin almost 4 yearsThe only solution that worked for me. I guess gradle plugin is broken
-
Jilles van Gurp almost 4 yearsI had to reopen the project. Intellij has loads of caching bugs that require stuff like this. Basically the gradle sync did not fix the project setup until it reopened the project.
-
geneSummons about 3 years3. Run tests using Intellij IDEA -- and run the test -- your "problem" will still be there and the test will fail. But Intellij will give you more "output". In my case, the stupid test author (me) forgot to give the test a void return type.
-
Siamak almost 3 years@geneSummons Kudos to you for this tiny soul saver comment
-
Anton Balashov over 2 yearsSeems fresh versions of Android Studio don't have this parameter there anymore. Any idea?
-
Zach over 2 yearsThanks Man - I had to switch out to use
useTestNG
inbuild.gradle