Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test Coverage not working in IntelliJ Idea

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 IntellijIdea 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. Any suggestions and help are really appreciated.

Thanks!

like image 794
Sushan Baskota Avatar asked Sep 01 '19 01:09

Sushan Baskota


People also ask

Why test coverage is not showing in IntelliJ?

From the main menu, select Run | Show Coverage Data ( Ctrl+Alt+F6 ). In the Choose Coverage Suite to Display dialog, select the checkboxes next to the necessary suites, and click Show selected. IntelliJ IDEA opens the coverage results for the selected test suites.

How do I enable code coverage?

Enable code coverage on your project. Right-click your project and select Properties > Code Coverage. Select Enable code coverage. Click OK.

How do you show test coverage?

You simply take: (A) the total lines of code in the piece of software you are testing, and. (B) the number of lines of code all test cases currently execute, and. Find (B divided by A) multiplied by 100 – this will be your test coverage %.


1 Answers

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.

like image 179
CrazyCoder Avatar answered Oct 12 '22 09:10

CrazyCoder