DEV Community

raquezha
raquezha

Posted on

4 1

JUnit5 Unit Testing, Test events were not received.

The Problem

I came from Junit4 testing, and I want to try Junit5 and started writing some unit tests and I'm curious why I received this message: ```Test

events were not received.


After some digging I've found out more detailed errors:
Enter fullscreen mode Exit fullscreen mode

FAILURE: Build failed with an exception.


So I google on how to solve the problem and stumble on this site [gradle.org site](https://docs.gradle.org/current/userguide/java_testing.html#using_junit5)


I just have to add this code to enable JUnit Platform to run my tests:

Gradle DSL (build.gradle)
Enter fullscreen mode Exit fullscreen mode

test {
useJUnitPlatform()
}

Kotlin DSL (build.gradle.kts)
Enter fullscreen mode Exit fullscreen mode

tasks.named("test") {
useJUnitPlatform()
}


But after adding those code another problem occurred:


Enter fullscreen mode Exit fullscreen mode


A problem occurred evaluating project ':app'.
"> Could not find method test()"


I've added this because maybe for some this is the solution but unfortunately this did not work for me. If above did not work for you can try the solution below.

#Solution
After digging a little because all of my searches were not working I stumble upon this stackoverflow [post](https://stackoverflow.com/questions/58168384/how-to-run-tests-by-gradle-instead-of-intellij-with-junit5-and-springboot2-in-mu) it turns out I'm missing one import!


I just add this missing dependency:
Enter fullscreen mode Exit fullscreen mode

testImplementation 'org.junit.jupiter:junit-jupiter:5.8.0-M1'

And after successful gradle sync, tadah!
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/826v4n82a2m87qbtjn2b.png)

I hope this helps someone fix this noob error.

--

Here's what I'm using
1. Android Studio Arctic Fox | 2020.3.1 Canary 15
2. Gradle 7.0
3. Kotlin 1.5.0
4. Dependencies
Enter fullscreen mode Exit fullscreen mode

testImplementation 'org.junit.jupiter:junit-jupiter:5.8.0-M1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.0-M1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.0-M1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.0-M1'


Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (2)

Collapse
 
thereprator profile image
Vikram Singh •

Hi rquezha,

Could you please help me with my stackoverflow question,
stackoverflow.com/questions/687508...

As i am also facing the same issue as yours, and had tried all those as well, but it fails.

Kindly assist.

Collapse
 
alicja99 profile image
Alicja Mruk •

Accidentally run into the same problem, thanks mate!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs