In this post, I will show you how to generate test coverage reports using the JsTestDriver. First of all, Let’s understand what is meant by “Test Coverage”. “Test Coverage” is one of the measures of software testing. It describes how much the source code of the program is tested.
The coverage criteria can be on the function level (Function coverage), on the statement level (Statement coverage), and on the code branch level (Branch coverage).
- Download the “coverage.jar” from http://code.google.com/p/js-test-driver/downloads/list
Add the coverage plugin declaration to the configuration file (
jsTestDriver.conffile) as follows:
... plugin: - name: "coverage" jar: "plugins/coverage.jar" module: "com.google.jstestdriver.coverage.CoverageModule"
--testOutput [output_folder]flag in the test running command. This will get the test coverage files in the
Currently, The JsTestDriver generates the test coverage files in LCOV format. Unfortunately, JsTestDriver does not generate HTML reports directly as shown in the figure below.
To generate the HTML reports from the LCOV files, you can use the LCOV visualizer, check it here: http://ltp.sourceforge.net/coverage/lcov.php.
The LCOV visualizer tool is working on Linux Redhat environment. To generate the report from the tool, execute this command on the
For more information about how to install the LCOV visualizer on Linux Redhat environment, and converting the LCOV files to HTML reports:
I wish that this tip can be useful.