IntelliJ IDEA 6.0: Code Coverage

July 4th, 2006 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!

Technorati tags: , , , ,

18 Responses to “IntelliJ IDEA 6.0: Code Coverage”

  1. Jesse Wilson Says:

    This is very, very hot.

  2. Andreas Andreou Says:

    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:

    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:

    Can we get a refund from Clover?

  5. christian Says:

    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:

    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:

    “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:

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

  9. Jerry K Says:

    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:

    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:

    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:

    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:

    How to save information about code coverage?

  14. John Nabil Says:

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

  15. Trejkaz Says:

    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:

    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:

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

  18. Oto \\\'tapik\\\' Buchta Says:

    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?

Leave a Reply