-
Notifications
You must be signed in to change notification settings - Fork 3
How to: Code Coverage
With the Angular CLI we can run unit tests as well as create code coverage reports. Code coverage reports allow us to see any parts of our code base that may not be properly tested by our unit tests.
To generate a coverage report run the following command in the root of your project:
ng test --watch=false --code-coverageWe could even chose to keep the watch on if the developer wants to see the various unit tests run in the the browser:
ng test --watch=true--code-coverageOnce the tests complete a new /coverage folder will appear in the project. This folder contains the index.html file, which contains a report with the source code and code coverage values.
Using the code coverage percentages we can estimate how much of our code is tested. Our team has decided to ensure that a minimum of 80% of the code must be tested for it to be merged and moved to production.
For this we added the following code in karma.conf.js:
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true,
thresholds: {
statements: 80,
lines: 80,
branches: 80,
functions: 80
}
}Note: This is likely to get changed as our understanding of node.js integration tests increases.
Install istanbul globally:
npm i -g istanbul
Install mocha globally:
npm i -g mocha
In the test folder, run:
istanbul cover mocha test.spec
- Srishti Hunjan shunjan@ufl.edu