I have an Angular app and I'm giving testing a go but it's a nightmare to find where the coverage is needed.
the output shows the following:
=============================== Coverage summary ===============================
Statements : 91.67% ( 22/24 )
Branches : 75% ( 3/4 )
Functions : 75% ( 3/4 )
Lines : 90.48% ( 19/21 )
================================================================================
Is there a way to see where these statements, branches, functions and lines are that are not covered?
e.g. some output that says
Statements:
1. file: some/file/name.js line:03
2. file: some/file/name.js line:06
Is that possible?
Thanks
Open the index. html file inside the /coverage folder to see a report with your source code and code coverage values.
If you want to reopen the Coverage tool window, select Run | Show Code Coverage Data from the main menu, or press Ctrl+Alt+F6 . The report shows the percentage of the code that has been executed or covered by tests. You can see the coverage result for classes, methods, and lines.
If you upgraded to Angular 11 recently, you might have noticed that karma-coverage-istanbul-reporter has been deprecated. It can simply be replaced with karma-coverage and by changing some things in karma. conf. js .
How is it measured? To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.
Angular CLI creates code coverage reports when using the following command (see Enable code coverage reports).
ng test --code-coverage
When the tests are complete, the command creates a new /coverage
folder in the project or it overwrites its content if it existed before. Open the index.html
file inside the /coverage
folder to see a report with your source code and code coverage values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With