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:
src/test/java
useJUnitPlatform()
result is the sameTest detection By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. This detection uses different criteria depending on the test framework used. For JUnit, Gradle scans for both JUnit 3 and 4 test classes.
I had this error with a similar setup, but couldn't solve it with the previous answers. Resolved it by doing this.
All credit to: https://linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With