Retrieving line coverage information

  • sbonacin83

    sbonacin83 - 2010-11-23

    I need to detect whether a specific line has been covered by a single test case. However I need to do this through code and not by looking at the HTML file. In other words, I want to write a function boolean covered(int lineno) that returns true if the line number lineno has been covered. How can I do this? It seems that the XML file does not contain this kind of information.
    Is the file format specified anywhere?


  • Marc R. Hoffmann

    You might get some ideas by looking at the EclEmma implementation ( EclEmma is a code coverage plug-in that integrates EMMA via its APIs. In case your application runs on top of the Eclipse IDE EclEmma itself offers handy APIs to retrieve line level coverage.

    *.es files are serialized Java objects. You can open them via this EMMA API call:

      File f = ...
      IMergeable data = DataFactory.load(f)[DataFactory.TYPE_COVERAGEDATA];


  • sbonacin83

    sbonacin83 - 2010-11-24


    Thanks for your answer.

    I need to detect the nodes where the paths of two different runs took different branches. Is that possible with EMMA? I guess EMMA creates CFGs and DFGs: are they available through API calls too?

    Are there any javadocs for EMMA? Where can I find them?


  • Marc R. Hoffmann

    Hallo Silviano,

    unfortunately EMMA does not support branch coverage. The implementation is based on basic blocks (see which does not require to construct call graphs at all (therefore also no API for this).

    AFAIK there is no JavaDoc published, but there is a source download and a public CVS repository.


  • sbonacin83

    sbonacin83 - 2010-11-25

    Hi Marc,

    Thanks for helping me out. I have another question: I am trying to run EMMA from within a program but I keep getting the "error": EMMA: no metadata collected at runtime . Here's my code:

          String filename = "";
          String[] args = new String[] {
              "-cp", "bin",
              "-sp", "src",
              "-out", filename,
              "-ix", "+program.Triangle",
          Command.create("run", "emmarun", args).run();

    If I run the same command from a shell it works correctly instead. Do know what could be the problem?


  • Marc R. Hoffmann

    EMMA installs a so called "shutdown hook" that is triggered at JVM shutdown and flushes execution data to disk. That's why no data is written as long as your program is running. Alternatively you might try to call


    from your program.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks