News Tips & Tricks

IntelliJ IDEA 6.0: Code Coverage

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

Discover more