"Test events were not received" when run tests using Intellij
TestingIntellij IdeaKotlinJunitTesting Problem Overview
I have a Kotlin project and when I run my JUnit tests, I can't see tests execution result in IntelliJ and get this message instead:
> test events were not received
I'm using this setup:
macOS Mojave
Intellij CE 2019.2
JDK 11.0.3
Kotlin 1.3.50
Gradle 5.2.1
JUnit 4.12
Can you help me?
Testing Solutions
Solution 1 - Testing
For me, the Same issue was occurring, below changes worked for me.
IntelliJ Version I am using: 2019.2.2
In IntelliJ IDE, Go to
File -> Settings ->Build,Execution, Deployment -> Build Tools -> Gradle
here in the Run test using:
dropdown selected option was: Gradle(default)
changed it to IntelliJ IDEA
Solution 2 - Testing
Update to 2019.2.2 or later, which contains the fix for the related issue.
A workaround is to run the tests using IntelliJ IDEA instead of Gradle by changing the delegation option.
Solution 3 - Testing
When trying to work out this problem for myself, I discovered JUnit 4 worked, but JUnit 5 reports "Tests were not received." Per petrikainulainen.net I found my solution.
> Even though Gradle 4.6 (and obviously all newer versions) has a native > support for JUnit 5, this support is not enabled by default. If we > want to enable it, we have to ensure that the test task uses JUnit 5 > instead of JUnit 4.
When I added the following code to Gradle, JUnit 5 worked.
test {
useJUnitPlatform()
}
Solution 4 - Testing
For anyone that is still facing this -
check if you have any compiler errors in the Build
tab.
Solution 5 - Testing
In my case I had an invalid Gradle JVM configuration (configured jdk was removed from filesystem).
To Fix it had to change Gradle JVM on File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM.
It was red due to an invalid JDK path.
IntelliJ version: 2019.2.3
Solution 6 - Testing
I often have to delete build and out folder to fix this problem ..
Solution 7 - Testing
For a Spring boot, gradle project using IntelliJ, my issue was that Spring Boot currently brings JUnit 5 with it. I had also manually installed JUnit 5 as well.
After deleting compile 'org.junit.jupiter:junit-jupiter-api:5.6.3'
in build.gradle
my tests began to work again.
Solution 8 - Testing
I was using facing the same issue even using IntelliJ IDEA 2019.2.4 (top answer said this was fixed on 2019.2.2). Turns out I had to Invalidate Caches / Restart...
before trying.
Solution 9 - Testing
For those who still might have this problem using IntelliJ & Kotlin:
Add the following lines to the build.grade.kts. I hope it helps some of you.
dependencies {
testImplementation(kotlin("test-junit5"))
testImplementation(platform("org.junit:junit-bom:5.7.0"))
testImplementation("org.junit.jupiter:junit-jupiter")}
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
PS: without adding the "task." before test{...} I was getting the following error!
> the function invoke() is not found
Solution 10 - Testing
make sure you are using the correct @Test annotation which is from org.junit.Test; Sometimes while auto importing it can get the annotation from some other library. for ex - org.junit.jupiter.api.Test;
Solution 11 - Testing
I ran into this issue and it turned out that I had written JUnit 4 tests in a module that was configured for JUnit 5. The solution was to use JUnit 5 imports in my test class:
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
Solution 12 - Testing
The problem occurred as I used both following plugins at the same time
plugins
{
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.7.RELEASE'
...
}
after deletion of the second one, the tests were found and executed.
Solution 13 - Testing
Answer
I know of some issues that occur when running Gradle together with the newest JDK versions (13 & 14). If you selected either version 13 or 14 of the JVM as the Gradle JVM try using either 8 or 11.
Switch the Gradle JVM to version 11:
File -> Settings -> Build Execution, etc -> Built Tools -> Gradle -> Gradle JVM
Explanation
I believe that by default Intellij will use the project SDK:
Project strcuture -> Project -> Project SDK
I've had this on several occasions now and picking version 11 of the JVM fixed things for me.
Worth noting is that for most of my project I'm using:
- Lombok
- Jackson
- Lombok plugin (Require annotation processing to be enabled)
I don't remember where I read it but I believe there were some issues with the lombok plugin + gradle + JVM version. I might revisit this answer if I can remember where I found the post about it.
Solution 14 - Testing
your most likey not tellinig the system how to run the tests.
on your class header define a test runner like this for example:
@RunWith(MockitoJUnitRunner::class)
class MYTest {//...}
or can define junitX runner , etc
Solution 15 - Testing
Try add
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.7.2")
if your tests use the older org.junit.Test
instead of org.junit.jupiter.api.Test
Solution 16 - Testing
This is the solution worked for me:
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
Switching Gradle JVM to: JAVA_HOME version 11.0.10 worked.
Solution 17 - Testing
Solution 18 - Testing
If you are using Kotlin DSL as your gradle script then adding the following did the trick for me:
tasks.withType<Test> {
useJUnitPlatform() // Make all tests use JUnit 5
}
Explanation: Above idiomatic Kotlin DSL makes all tasks with type Test to use JUnit 5 platform which is required for test to work.
Solution 19 - Testing
I was also struggling, and no answer online I found worked for me, and I eventually realized it was due to a System.exit(0) call. As a result, all tests would silently stop after calling whatever code with the exit call and show that test as "ignored" in IntelliJ.
Solution 20 - Testing
For me, this is helpful to click "Help -> Check for Updates..."
[Help -> Check for Updates...][1]