Test coverage not working in IntelliJ IDEA
Asked Answered
M

2

6

While running the application with coverage, coverage is not showing. I see the difference in my logs compared to working machine logs is coverage-agent.jar is not logged in my console logs. Does anyone know the fix?

I am running Intellij IDEA Ultimate 2019.2.1 and JDK version 1.8.221. I tried every option like uninstalling the IntelliJ, tried on community edition too, downgrading to a lower version, changing JDK version to higher 9 and lower 1.8.211, checked the plugins, also deleted the Intellij Settings folder but none of them worked. I reached to IntelliJ support team they also suggested to delete the IntelliJ settings folder, but that didn't work.

Here is the log while running in coverage mode. Here we don't see coverage-agent jar invocation log.

"C:\Program Files\Java\jdk1.8.0_221\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Users\<User> Baskota\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6603.8\lib\idea_rt.jar=52886:C:\Users\<User> Baskota\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6603.8\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\<User> Baskota\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6603.8\lib\idea_rt.jar;C:\Users\<User> Baskota\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6603.8\plugins\junit\lib\junit-rt.jar;C:\Users\<User> Baskota\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6603.8\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\jaccess.jar;C:\Program 

And this is the console log for the same project running on the different machine with same IntelliJ IDEA version and JDK version. Here coverage is working fine and the log has coverage-agent jar invocation log.

"C:\Program Files\Java\jdk1.8\bin\java.exe" -ea -javaagent:C:\Users\<User>\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6262.58\lib\intellij-coverage-agent-1.0.508.jar=C:\Users\<User>\AppData\Local\Temp\coverage1args -Didea.test.cyclic.buffer.size=1048576 -javaagent:C:\Users\<User>\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6262.58\lib\idea_rt.jar=63530:C:\Users\<User>\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6262.58\bin -Dfile.encoding=UTF-8 -classpath "C:\Users\<User>\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6262.58\lib\idea_rt.jar;C:\Users\<User>\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6262.58\plugins\junit\lib\junit-rt.jar;C:\Users\<User>\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6262.58\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Java\jdk1.8\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8\jre\lib\ext\jaccess.jar;C:\Program 

Has anyone faced this kind of weird issue? My coverage was working until few days earlier.

Merrymaking answered 1/9, 2019 at 1:43 Comment(0)
P
4

Code coverage may not work if the path to the coverage library contains spaces. You can tell it by the following line in idea.log:

2019-08-31 19:30:17,148 [ 130152]   INFO - ij.execution.JavaExecutionUtil - agent not used since the agent path contains spaces: C:\Users\Some User Name With Spaces\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.6603.8\plugins\coverage\lib
One can move the agent libraries to a directory with no spaces in path and specify its path in idea.properties as java.test.agent.lib.path=<path> 

The workaround is to copy the specified lib directory into some new location without spaces, for example c:\coverage-lib. Then in Help | Edit Custom Properties specify this new location:

java.test.agent.lib.path=c:/coverage-lib

You also need to copy IDEA_HOME\lib\intellij-coverage-agent-1.0.508.jar (the version may be different) to the same location without spaces.

Restart IntelliJ IDEA.

Paisano answered 1/9, 2019 at 4:8 Comment(3)
What a coincidence I got the same response from IntelliJ support team too, and Yes it was issue with the coverage plugins being in the directory name having space. After copying the coverage\lib to some non-space directory with one extra intellij-coverage-agent.jar which has not on coverage lib folder it worked. Thanks for your prompt answer. :)Merrymaking
@SushanBaskota That response was by me too ;)Paisano
Wow! Thanks a lot. Really appreciate your help.Merrymaking
S
-1

I ran into this issue too. For me the problem was that my package name of the test class did not match the package name of the service class. Fixing these to match each other resolved it for me.

Sawyer answered 26/8, 2022 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.