# Junit 5 test suites not running

**URL:** <https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977>\
**Category:** Help/Discuss\
**Created:** [August 29, 2019, 8:24am UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977 "2019-08-29T08:24:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)\
**Post date:** [August 29, 2019, 8:24am UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977/1 "2019-08-29T08:24:56Z")

</div>

I’m migrating my junit test cases from 4 to 5.  
In Junit 4 I have test suites.  
The new Junit 5 “test suites” runs fine from Eclipse but not from commandline.

Windows 10, gradle 5.5.1, Java 8

Build.gradle snippet

```
dependencies {
    implementation 'junit:junit:4.12'
    implementation 'org.junit.jupiter:junit-jupiter-api:5.5.0'
    implementation 'com.sun.xml.parsers:jaxp-ri:1.4.5'
    implementation 'org.apache.commons:commons-csv:1.6'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0'
    testImplementation 'org.junit.platform:junit-platform-suite-api:1.5.0'
    testImplementation 'org.junit.platform:junit-platform-runner:1.5.0'

    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.5.0'
}

test {
    useJUnitPlatform()
    include '**/AllTests.class'
}

```

The Junit suite snippet:

```
package dk.junit.run;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.runner.RunWith;

import dk.progress.JobTest;
import dk.progress.TaskTest;

@RunWith(JUnitPlatform.class)
@SelectClasses({
    TaskTest.class,
    JobTest.class
})
public class AllTests {
}

```

Gradle runs zero test.

Is there a way that I can the the test suites in Junit 5 and run it from gradle?

---

<div class="post-metadata">

**Author:** ![Comnir](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@Comnir](https://discuss.gradle.org/u/Comnir)\
**Post date:** [August 30, 2019, 6:17pm UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977/2 "2019-08-30T18:17:27Z")

</div>

I think the issue is with your `include '**/AllTests.class'`, which doesn’t include the selected classes TaskTest and JobTest.

---

<div class="post-metadata">

**Author:** ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)\
**Post date:** [August 31, 2019, 8:15am UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977/3 "2019-08-31T08:15:19Z")

</div>

If I run the AllTests.class in Eclipse(2019.6) then TaskTest and JobTest are also run.  
But that does not work with Gradle.

If I remove the include statement in Gradle then TaskTest and JobTest are run. AllTests is not run properly because is doesn’t have a method annotated with @Test.

But I don’t understand why the @SelectClasses annotation doesn’t work with Gradle.

---

<div class="post-metadata">

**Author:** ![Jazzepi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jazzepi/32/7497_2.png) [@Jazzepi](https://discuss.gradle.org/u/Jazzepi)\
**Post date:** [September 3, 2019, 1:41pm UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977/4 "2019-09-03T13:41:22Z")

</div>

Check to make sure that you’re using the `org.junit.jupiter.api` package for the `@Test` annotation. Junit didn’t switch the actual annotation name going from 4 -\> 5 like they did for most of the rest. It’s very easy to accidentally use the wrong import.

---

<div class="post-metadata">

**Author:** ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)\
**Post date:** [September 4, 2019, 11:22am UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977/5 "2019-09-04T11:22:01Z")

</div>

The @Test is not the problem.

The problem is that AllTests is a Junit 4 construction. And it can’t be run with Junit 5.  
Eclipse is smart enough to figure this out and use the right “runner”.

The solution is to delete the AllTests.java and remove the include statement in the gradle build file.

I just found out that I can right-click on a package or the test source folder and select Run As Junit Test to get a similarly behaviour as my AllTests.

---

<div class="post-metadata">

**Author:** ![Jazzepi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jazzepi/32/7497_2.png) [@Jazzepi](https://discuss.gradle.org/u/Jazzepi)\
**Post date:** [September 4, 2019, 11:34am UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977/6 "2019-09-04T11:34:20Z")

</div>

I had the exact same problem except it was with the @test annotation from junit 4 and intellji running it when Gradle was looking for junit 5 annotations and silently passing everything by executing none of the tests.

---

<div class="post-metadata">

**Author:** ![TheReprator](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@TheReprator](https://discuss.gradle.org/u/TheReprator)\
**Post date:** [August 13, 2021, 7:01am UTC](https://discuss.gradle.org/t/junit-5-test-suites-not-running/32977/7 "2021-08-13T07:01:03Z")

</div>

i am trying to create a test suite for Unit test of android application, but it always fails with different kinds of configuration error, one among that is as follows,

Error: Test events were not received android  
FAILURE: Build failed with an exception.

- What went wrong:  
Execution failed for task ‘:appModules:factList:testDebugUnitTest’.

> No tests found for given includes: [reprator.wipro.factlist.FactListTestSuite]  
> (filter.includeTestsMatching)  
> RepoDetails: [https://github.com/TheReprator/Wipro/tree/junit5](https://github.com/TheReprator/Wipro/tree/junit5)

Branch: junit5

TestSuite Class: [https://github.com/TheReprator/Wipro/blob/junit5/appModules/factList/src/test/kotlin/reprator/wipro/factlist/FactListTestSuite.kt](https://github.com/TheReprator/Wipro/blob/junit5/appModules/factList/src/test/kotlin/reprator/wipro/factlist/FactListTestSuite.kt)

I had tried many efforts and references, some of them are as follows,

> **[JUnit5 Unit Testing, Test events were not received.](https://dev.to/raquezha/junit5-unit-testing-test-events-were-not-received-37dc)**
>
> JUnit5 Unit Testing noob error

> <https://stackoverflow.com/questions/57795263/test-events-were-not-received-when-run-tests-using-intellij>

My whole code works perfectly with junit4 in master branch.  
Stackoverflow: [Junit5 testSuite with SelectClasses not working in android unit test - Stack Overflow](https://stackoverflow.com/questions/68750803/junit5-testsuite-with-selectclasses-not-working-in-android-unit-test)

Please assist.
