IntelliJ IDEA 6.0: Code Coverage

Posted on by Maria Khalusova

In forthcoming IntelliJ IDEA 6.0 release a new tool will be available. It aims to measure the code coverage for your unit tests or tests written as simple applications with the main() method. The engine that performs code coverage in IntelliJ IDEA is based on the EMMA open-source toolkit.
The feature as implemented by IntelliJ IDEA brings several technical innovations to the Java code coverage field.
The most important of them are:

  1. On-the-fly code coverage execution with no classes pre scanning phase
    IntelliJ IDEA has no need in static classes instrumentation making use of instrumentation concept introduced in Java 5.0. Moreover, IntelliJ IDEA already knows the structure of your project, so it can calculate the package coverage statistics based not only on those classes that have been instrumented, but taking into account all compiled classes for the package. Essentially this brings lazy coverage calculation concept into action and ensures low run time overhead.
  2. Correct coverage information displayed for files edited after coverage statistics has been gathered
    How is it possible? Well, again this is a result of a tight integration of coverage support with the rest of IntelliJ IDEA infrastructure. Here the result is obtained by collecting the information on the difference between the current file version and the one created at the moment coverage was run (taken from the local VCS).

To get the feeling of the code coverage, you just need to configure this feature and run your tests or applications. You can access this feature by selecting Run | Edit Configurations (or by pressing Shift + Alt + F10). The Run/Debug Configurations dialog appears where you can enable and configure the feature.

To run the coverage measuring, simply run or debug the configuration.
Whereupon, the statistics on the lines covered can be displayed in the Project View by selecting View-> Show Coverage Information or pressing Ctrl+Alt+F6 in the default keymap.

Also right in the editor you’ll see whether the lines were covered or not (they are marked green and red, respectively). The yellow mark indicates that the line was executed “partially”, for example, if only one condition from the if statement was checked.

The feature is already available in the latest EAP version. Join EAP now!

Comments below can no longer be edited.

25 Responses to IntelliJ IDEA 6.0: Code Coverage

  1. Jesse Wilson says:

    July 4, 2006

    This is very, very hot.

  2. Andreas Andreou says:

    July 4, 2006

    What exactly is hot?
    Using EMMA while running your main() has always produced interesting reports… It can even provide bottleneck hints…
    Or show which parts of your app your users use most…
    But anyway, i guess it’s a welcome addition to an excellent product.

  3. Eric Burke says:

    July 5, 2006

    I use Emma, yet I’m very excited about this new IDEA feature. This feature is *hot* because it is incorporated right into the editor, and does not require any effort to configure and run. Running Emma standalone is “OK” once you configure your Ant buildfile and classpath, but it is still awkward to go to a web browser and sift through the reports it generates. It will be much faster to test/run/code/view coverage right in IDEA without the context switch to go to a web browser. Consider Javadocs…how often do you leave IDEA and go to a web browser now that docs are incorporated directly into the editor?

  4. ZipPaDeDuda says:

    July 13, 2006

    Can we get a refund from Clover?

  5. christian says:

    August 2, 2006

    Is it possible to select the packages recursively? If not that would be great…

    And you should really remove that spam and improve the capcha!

  6. Eugene Vigdorchik says:

    August 2, 2006

    Actually the packages are unconditionally selected recursively. If you want to make a nonrecursive selection, you can select classes in that package instead.

  7. Alexey says:

    August 30, 2006

    “Code coverage is supported for jre 5.0 or higher” – a crash of all my hopes. Is it because you use those new JVM runtime hooks? EMMA claims they support JDK 1.2+…

  8. Anthony Browne says:

    November 2, 2006

    Will the EMMA code coverage be enabled for the TestNG plugin tab?

  9. Jerry K says:

    November 3, 2006

    Wow! You JetBrains guys have done it again. I just discovered this feature entirely by accident… Thanks for continuing to make IDEA better with every release—I’ve been a fan since 2002.

  10. Fan of Don Lapre says:

    November 14, 2006

    Thanks JetBrains for the new features. I haven’t used IntelliJ IDEA for a while but stumbled across this and thought I would check it out again. Will be looking for new updates in the future. I forgot how much fun this is.

    Larisa
    Fan of Don Lapre
    http://www.larisajoyreilly.com
    larisa@larisajoyreilly.com

  11. ravin says:

    December 28, 2006

    sir,
    I would like to know that how to install and to use of Intelli IDEA 6.0

    indra_ravin@yahoo.com

  12. Zain Mecklai says:

    July 6, 2007

    I’m curious if there are any plans to provide code coverage data for a remotely attached application since not all applications are pure Java applications with a main() method.

  13. Roman says:

    August 1, 2007

    How to save information about code coverage?

  14. John Nabil says:

    February 7, 2008

    How can i get html report from it ? emma has this feature.

  15. Trejkaz says:

    April 24, 2008

    I’m getting a yellow on a line like this:
    reader.close();

    How exactly can a line like this be partially executed?

  16. Sean Kleinjung says:

    June 2, 2008

    Trejkaz: I would assume it is because your tests did not execute the case where the close method throws an IOException, but I cannot say for sure if this is the cause.

  17. sam says:

    August 4, 2008

    Is there any way to get a code coverage report?
    Is there any additional documentation for this feature?

  18. Oto \'tapik\' Buchta says:

    August 20, 2008

    I have a simple question – is it possible to measure code coverage of servlet/EJB from IDEA? If yes, please, could you help me with JBoss configuration?

  19. Sushil says:

    February 22, 2010

    Can someone please let me know how to generate code coverage report probably in html format using EMMA in idea. I am able to generate the code coverage numbers but i have to look into the class browser window and see for each class, which is not a very efficient way. I need to see a consolidated report for my entire project. Is there any way to do that. Please reply back if you know how to do it.

  20. adeveloper says:

    December 4, 2010

    is there a way to enable the code coverage in junit test by default? It is annoying to enable it for each test.

  21. adeveloper says:

    December 4, 2010

    I think i found it.
    Run –> Edit Configurations –> Junit (right click) –> Edit Default –> check the Record code coverage information.

  22. basha says:

    June 15, 2011

    coverage.ec is not generating. I am trying my application in tomcat.

    I have done the following steps:
    1. I have deployed my application in tomcat
    2.i have copied emma.jar to C:Program FilesJavajre1.5.0_21binlibext

    3. My tomcat5w.exe, contain the following info:
    JVM as: C:Program FilesJavajre1.5.0_21binclientjvm.dll
    Java Options:
    -Demma.coverage.out.file=D:Tomcat 5.5emmacoverage.ec
    -Demma.coverage.out.merge=true

    4. Now i have instrumented the deployed application as below.
    java -cp emmar.jar emmae instr -m overwrite -cp “D:Tomcat 5.5webappsROOTWEB-INFclassescom”
    and coverage.em has generated in C:Program FilesJavajre1.5.0_21

    5.Now i have started my tomcat and did some transaction.
    when i see in stdout.logs ,i am getting
    EMMA: collecting runtime coverage data …

    EMMA: runtime controller started on port [47653]

    6.Stopped the tomcat
    7.i tried to find coverage.ec in D:Tomcat 5.5bin
    and also in C:Program FilesJavajre1.5.0_21

    but i could not found this file.

    8.And also tried the application to run from command line prompt,there also i couldnot found the file.

    9.i also set my jre path java_home in environment variables

  23. Stein Johansen says:

    November 16, 2011

    This looks very good, and merge of tests when you run multiple seems very good.
    Though… I could not run more than a single test-class at time, so all in all, it will not be useful before its possible to mark the whole test-suite and run it towards the application.
    Hope it comes soon, then this will be a very useful tool 🙂

  24. Andrew Mackenzie says:

    October 16, 2013

    I am completely stuck on how to enable coverage in Android instrumentation test tests. I see the coverage option in JUnit tests but not in my (working) Android tests.

    I´ve searched a lot on the web and your own site and can only find pages for Junit tests.

  25. cleanCode says:

    April 20, 2015

    Does anybody know where i can see the line- and branch-Coverage in percent?

Subscribe

Subscribe for updates