04.2 Code Coverage - medullan/mean GitHub Wiki

Code Coverage for Functional Tests

If you need code coverage to see what code is being covered when your functional tests are run then there are two grunt tasks setup to aid you with this. In addition, the server must be started in an environment variable COVERAGE set to 'true' in order to instrument and capture coverage data.

The environment variable also tells the app to add a /coverage endpoint to the application which will enable our build tasks to interface with the application to collect coverage data.

An Angularjs Utility module is also added to the application when the environment variable is set. The module will be executed each time a robot test triggers a TearDown. Its purpose is to add UI code coverage to the overall istanbul report after the functional tests have been executed. This module can be found at the following location: /public/lib/util/addCoverage.util.js

View the istanbul-middleware to understand the setup and how coverage data is collected

The output folder for these coverage reports is:

.reports/coverage/robot

Local Execution

This will start a server locally on port 3000 in the background then run functional tests against this server with a coverage report generated at the end. Once complete, the task will kill the local server.

To execute this task, run:

$ grunt test:robot:local

Remote Execution

Remote execution of the Robot Test Code Coverage task assumes the server is already running and is giving an ok response. When it is executed, it verifies the /coverage endpoint is available before actually executing anything. If it is not giving an ok response, then no tests or coverage reporting will be done.

To execute this task, run:

$ grunt test:robot --host=http://yourhost.com

To see more command line arguments, please view the Command Line Arguments Section