Tutorial: Java Code Coverage With Emma: Modified Version of Emma - Jar
Tutorial: Java Code Coverage With Emma: Modified Version of Emma - Jar
Tutorial: Java Code Coverage With Emma: Modified Version of Emma - Jar
Overview
This document introduces how to generate Java code coverage reports of your tests using EMMA.
Contents
What is Emma? Before you Start Generating a Code Coverage Report Interpreting the Coverage Report How to setup and run Emma in QApache? References
What is Emma?
Emma is an open source Java code coverage analysis tool. It allows you to identify what code paths that have and have not been executed. It generates an HTML report which can help developers easily identify what code they have not tested. Managers can use the reports to judge how much of the overall code is covered by tests.
version of emma.jar.
1. Create a library in project settings for Emma. 2. Add -Demma.coverage.out.file=/home/alawang/jdevhome/jdev/myclasses/coverage.ec to your Java Options. 3. In Tools-> Preferences, change the OC4J Shutdown option to "Shutdown Gracefully First, Forcefully Subsequently". Emma will only dump code coverage stats when java exits gracefully. This step is required if you run OA or JSP pages during your code coverage testing. 4. Setup two external tools in JDeveloper to simplify the execution of Emma. Go Tools -> External Tools -> Add. Ext Tool 1 - Emma Instrumentation Display -> Menu Caption: Emma Instrumentation For detail tab, see the following screen shot. Make sure you add all the arguments in that order:
Ext Tool 2 - Emma Report Display -> Menu Caption: Emma Report For detail tab:
Note: Default project sourcepath is a predefined item. You should click Add button to choose it instead of Add Text like all others.
5. Create filters.txt. In this file, you can speicify the class files you will gather code coverage data. You can put one line for each class files' full class name, or you can use wildcard. Check Emma document for more details.
For more details about these setting and how to tailor them for your own project, please check Emma's website.
ms}
If you go to /home/alawang/jdevhome/jdev/myclasses, you will see a new file coverage.em was created. It will be used to generate reports.
Now Emma already instrumented your class files and embedded some additional information in it. This is similar with using -g with javac or gcc.
You will see coverage.ec in /home/alawang/jdevhome/jdev/myclasses. This will also be used to generate reports. Generate Report Tools -> Emma Report. Wait for the console window to close. You will see the following in output window of JDeveloper:
EMMA: processing input files ... EMMA: 2 file(s) read and merged in 330 ms EMMA: writing [html] report to [/home/alawang/jdevhome/jdev/myclasses/coverage/index.html] ...
Overall Coverage
The first page is overall coverage. It tells you the coverage for all packages under investigation. For each package, it will should the following numbers: Column Meaning class % How many percent of classes were involved method % How many percent of methods were called block % How many blocks of code were executed? This is a proprietary gauge of Emma
line
% How many lines were executed? Excluding comment lines and those un-executable lines
Package Coverage
Click any package it will give you details about that package. Columns are the same.
File Coverage
Click any file it will give you details about that file. Columns are the same. On the top, you will see the statistics for each method. On the lower half, you will see the source code of that file. For lines covered, it will be in green. Uncovered will be in red. Partially covered will be in yellow. Developers can easily find out where is the blind spots for this execution.
Step 2: Instrument the code : Click Tools -> Emma Instrumentation For how to define 'Emma Instrumentation' external tool, please refer to the Configure Emma In JDeveloper section above. Step 3: Copy the instrumented class files to QApache. You can either copy the class files into APPL_TOP/java, or you can configure a prepend class path and put the instrumented class files there. You can also modify the command line to instrument class files and place them into the QApache APPL_TOP/java or prepend class path directly. Then you won't need Step 3. Step 4: Restart the QApache port This will force JServ to load new class files instead of keep using the old class files . Step 5: Run your test as usual. Step 6: Go to emmactrl.jsp and choose 'Save the coverage data' The emmactrl.jsp can be found at http://qapache.us.oracle.com:<my_port>/OA_HTML/emmactrl.jsp Step 7: Generate report: Run Tools -> Emma Report.
References
For more details about Emma, please visit: http://emma.sourceforge.net/