Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No tests found for given includes" when running Gradle tests in IntelliJ IDEA

Tags:

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
like image 827
Arrovil Avatar asked Feb 14 '20 14:02

Arrovil


People also ask

How does gradle find tests?

Test 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.


1 Answers

I had this error with a similar setup, but couldn't solve it with the previous answers. Resolved it by doing this.

  1. File > Setting (Ctrl+Alt+S)
  2. Build, Execution, Deployment > Build Tools > gradle
  3. Run Tests using: Intellij IDEA

All credit to: https://linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/.

like image 184
Jonathan Lee Avatar answered Sep 18 '22 14:09

Jonathan Lee