Even though code coverage metrics can be misleading, they are still vital. While code coverage is typically associated with unit tests, it is equally easy to generate code coverage metrics from integration tests. And it is trivial to combine multiple code coverage reports into a single report that includes all your unit and integration tests, thereby providing a complete picture of exactly what code is covered by your full suite of tests.
Code coverage measures if, and if so, how many times, a line of code is executed. This is useful for measuring the efficacy of your test code. In theory, the more lines that are “covered”, the more complete your tests are. However, the link between code coverage and test completeness can be tenuous.
Here is a simple Node.js function that returns the current stock price of a given symbol:
/** * Return current stock price for given symbol * in the callback * * @method getPrice * @param symbol <String> the ticker symbol * @param cb <Function> callback with results cb(error, value) * @param httpObj ...