How do I generate code coverage information for the Mojarra source code?

These instructions show how to use the Cobertura code coverage tool with the JSF source code.  These instructions are tailored for Unix/Linux environment, but scripts are available for Windows.

1. Obtain a GlassFish zip bundle.

2. Set COBERTURA_PATH environment variable to point to top level Cobertura install directory.  For example: /Home/cobertura-1.9.4.1

3. Instrument the jsf-api.jar and jsf-impl.jar files for the code coverage tool using the [^instrument.sh]  script:

  •     ./instrument.sh glassfish.zip 

This will create instrumented-glassfish.zip  file  that contains the instrumented jsf-api.jar and jsf-impl.jar files

4. Unzip the instrumented-glassfish.zip file.  You will see a glassfish3 directory.

5. Start up the instrumented GlassFish:  ./glassfish3/glassfish/bin/asadmin start-domain --verbose=true

6. Set up JSF tests to run in no cluster mode against the instrumented GlassFish instance:

  • In build.properties, make sure this setting is there:  container.name=glassfishV3.1_no_cluster
  • In build.properties, make sure the tests are set up to run against the instrumented GlassFish instance:  container.home=<instrumented GlassFish instance>

7. Run the JSF tests from the top level:

  • ant test

8. When the tests complete, shut down the server gracefully - asadmin stop-domainDo not kill the server.  Look for cobertura.ser data files.  These files are the data files containing coverage information and they are used to generate the report.  You will usually find two of them.  You can check by going to the directory where the glassfish3 instrumented GlassFish directory is.  For example, if you have the following:

/home/glassfish3

cd home;  find . -name *.ser

You will usually find one in the directory containing the glassfish3 subdirectory (in this case under home), and the other one will be under:

glassfish3/glassfish/domains/domain1/config/

9. Merge the datafiles (cobertura.ser files) into one using the Cobertura merge tool under the top level Cobertura install directory:

./cobertura-merge.sh --datafile <merged datafile> <datafile1> <datafile2>..

For example:

./cobertura-merge.sh --datafile /Home/instrumented/jsf-cobertura.ser /Home/cobertura.ser /Home/glassfish3/glassfish/domains/domain1/config/cobertura.ser

10. Create the report files from the merged datafile:

./cobertura-report.sh --format html --datafile /Home/instrumented/jsf-cobertura.ser --destination /Home/reports --basdir /Home/mojarra/trunk/jsf-api/src/main/java /Home/mojarra/trunk/jsf-ri/src/main/java

The destination specifies where you want the report files to go.  The basdir specifies the top level source directory locations that will enable you to view source files from the reports.