If you want to see overall test coverage statistics than of course in Angular CLI you can just type, and see the bottom of your command prompt window

ng test --code-coverage

result:

if you want to see component's individual coverage of tests follow these steps.

  1. npm install --save-dev karma-teamcity-reporter

  2. Add require('karma-teamcity-reporter') to list of plugins in karma.conf.js

  3. ng test --code-coverage --reporters=teamcity,coverage-istanbul

note that list of reporters is comma-separated, as we have added a new reporter, teamcity.

after running this command you can see the folder coverage in your dir and open index.html for a graphical view of test coverage.

You can also set the coverage threshold that you want to achieve, in karma.conf.js, like this.

coverageIstanbulReporter: {
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true,
      thresholds: {
        statements: 90,
        lines: 90,
        branches: 90,
        functions: 90
      }
    },
Answer from ahmadalibaloch on Stack Overflow
🌐
Angular
angular.dev › guide › testing › code-coverage
Code coverage • Angular
Code coverage reports show you any parts of your code base that might not be properly tested by your unit tests.
🌐
Testing-angular
testing-angular.com › measuring-code-coverage
Measuring code coverage – Testing Angular
February 17, 2021 - In Angular’s Karma and Jasmine setup, Istanbul is used for measuring test coverage. Istanbul rewrites the code under test to record whether a statement, branch, function and line was called. Then it produces a comprehensive test report.
Discussions

Code Coverage For Angular Templates?
It's not usually done. It might be possible to do something with the ivy codegen (I don't think anyone has yet), but I'm not sure about that, and I don't think it would be that useful even if it did work. As much as possible try to leave logic out of your template. Yes you need *ngIf, *ngFor, etc, but as much as possible try to have them work on plain booleans, simple equality checks, arrays, etc with all the real logic in your component code or pipes were they can be tested. More on reddit.com
🌐 r/angular
16
10
May 18, 2020
angular 13: --code-coverage prints Coverage summary with Unknown%
Bug report Command (mark with an x) new build serve test e2e generate add update lint extract-i18n run config help version doc Is this a regression? Yes, the previous version in which this bug wa... More on github.com
🌐 github.com
6
November 13, 2021
How to get code coverage for Angular 16+ Jest
ng test —code-coverage i suppose More on reddit.com
🌐 r/Angular2
5
1
December 14, 2023
How do you measure code coverage on bitbucket?
There are widgets for bitbucket for example sonarCloud that can show coverage for PRs More on reddit.com
🌐 r/angular
9
5
September 6, 2020
🌐
Angular
v17.angular.io › guide › testing-code-coverage
Code coverage
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular.
🌐
TutorialsPoint
tutorialspoint.com › angular_cli › angular_cli_code_coverage.htm
Angular CLI - Code Coverage
It is used to measure how many parts (or percentage) of your Angular codebase are executed by running the unit or integration test. It is also known as Test Coverage. Usage! The main purpose of Code Coverage is to provide coverage reports that ...
🌐
Angular
v18.angular.dev › guide › testing › code-coverage
Code coverage • Angular
Code coverage reports show you any parts of your code base that might not be properly tested by your unit tests.
🌐
Daniel Kreider
danielk.tech › home › angular-code-coverage
Angular Code Coverage (How to measure and use) | Daniel Kreider
December 9, 2024 - To do this, we're going to set up a code coverage badge in our README file. This will let us see at a quick glance how much of the code in our repository is currently tested. ... We will add a JSON reporter to the reporters array.
Find elsewhere
🌐
Daniel Kreider
danielk.tech › home › how-to-set-up-angular-code-coverage-in-vs-code
How to set up Angular code coverage in VS Code | Daniel Kreider
Run the following command in the root directory of your project to generate the coverage folder that Coverage Gutters uses to give us a code coverage report. ... And last of all, use the CTRL + SHIFT + P shortcut to open the commands window and select Coverage Gutters: Watch to show the code coverage status in Visual Studio Code. Don't forget that Angular code coverage isn't a silver bullet.
🌐
Medium
dkreider.medium.com › how-to-set-up-angular-code-coverage-in-vs-code-dbdceaac8951
How to set up Angular code coverage in VS Code | by Daniel Kreider | Medium
January 29, 2024 - Now, when you restart the Angular testing process, you’ll see a new folder in your project called coverage. This is the code coverage report for your Angular application.
🌐
O'Reilly
oreilly.com › library › view › angular-6-for › 9781786462909 › b6420576-d34b-4920-91c9-d529c678b8fc.xhtml
Code coverage report - Angular 6 for Enterprise-Ready Web Applications [Book]
May 31, 2018 - In order to generate the report for your app, execute the following command from your project folder: $ npx ng test --browsers ChromiumNoSandbox --watch=false --code-coverage
Author   Doguhan Uluca
Published   2018
Pages   512
🌐
Coryrylan
coryrylan.com › blog › enforcing-code-coverage-in-angular-cli-projects
Enforcing Code Coverage in Angular CLI Projects - Angular 17 | 16
November 24, 2023 - coverageIstanbulReporter: { reports: [ 'html', 'lcovonly' ], fixWebpackSourcePaths: true, thresholds: { statements: 80, lines: 80, branches: 80, functions: 80 } }, Under thresholds we can tell Karma our test runner to have certain minimum thresholds for our code coverage. If our code coverage drops below these percentages, Karma will throw an error and fail the build. With the Angular CLI, we can get fantastic tooling for our client-side applications.
🌐
Code with Jason
codewithjason.com › home › how to add a test coverage report to an angular cli project
How to Add a Test Coverage Report to an Angular CLI Project - Code with Jason
January 12, 2018 - $ npm install karma karma-jasmine karma-chrome-launcher karma-jasmine-html-reporter karma-coverage-istanbul-reporter Then run ng test. $ ng test --code-coverage Then run the server that shows you your report.
🌐
Angular Minds
angularminds.com › blog › methods-to-increase-code-coverage-in-angular
Methods to Increase Code Coverage in Angular
October 3, 2024 - Code coverage is typically obtained by using a code coverage tool. These tools run alongside your tests and monitor which parts of the code are executed. The tool then produces a report detailing the coverage.
🌐
Reddit
reddit.com › r/angular › code coverage for angular templates?
r/angular on Reddit: Code Coverage For Angular Templates?
May 18, 2020 -

Hello! I have done a decent amount of TDD-style coding on React projects where everything can be treated as a JavaScript function in some ways. We like to use the code coverage report as a tool to see where we are missing unit tests. The idea is that if you don't know what test to write next, just look at the code coverage report to see what still needs to be verified by automated tests.

With Angular though, a lot of the logic is moved to the HTML template files (ngIf, ngFor, etc). I am wondering if there is a way to have these html files show up on the code coverage reports for Angular? Is this a normal thing to do / want? Thanks!

🌐
Medium
medium.com › ngconf › angular-unit-testing-code-coverage-lies-603c6c85f801
Angular Unit Testing Code-Coverage Lies | by Jared Youtsey | ngconf | Medium
September 15, 2021 - Here we start to see how we can misinterpret the meaning of a code-coverage report. The report only shows us what lines were executed, not what lines were tested. In Angular, when you compile a component in a unit test ngOnInit and everything it calls will get “covered” immediately.
🌐
Medium
manivelarjunan.medium.com › angular-7-unit-testing-code-coverage-5c7a238315b6
Angular 7 + unit testing + code coverage | by Manivel Arjunan | Medium
December 29, 2018 - Open the index.html file in your favorite browser to view the test case coverage for all the files in the project. ... The TestBed is the most important of the Angular testing utilities. It creates a dynamically-constructed Angular test module that emulates an Angular @NgModule.TestBed.configureTestingModule() method takes a metadata object that can have most of the properties of an @NgModule.
🌐
GitHub
github.com › molily › testing-angular › blob › main › measuring-code-coverage.md
testing-angular/measuring-code-coverage.md at main · molily/testing-angular
In Angular’s Karma and Jasmine setup, Istanbul is used for measuring test coverage. Istanbul rewrites the code under test to record whether a statement, branch, function and line was called. Then it produces a comprehensive test report.
Author   molily
🌐
Medium
medium.com › @dijin123 › angular-unit-testing-code-coverage-report-in-azure-devops-build-pipeline-a062c881609c
Angular Unit Testing Code Coverage Report in Azure DevOps Build Pipeline | by Dijin Augustine | Medium
February 4, 2022 - steps: - task: PublishTestResults@2 displayName: 'Publish Test Results $(Build.SourcesDirectory)/Client/SampleApp/projects/web-app/test_report/TESTS-*.xml' inputs: testResultsFiles: '$(Build.SourcesDirectory)/Client/SampleApp/projects/web-app/test_report/TESTS-*.xml' Modify the Publish Code Coverage Task in Azure Pipeline,
🌐
GitHub
github.com › angular › angular-cli › issues › 22161
angular 13: --code-coverage prints Coverage summary with Unknown% · Issue #22161 · angular/angular-cli
November 13, 2021 - $ ng test --no-watch --no-progress --browsers=ChromeHeadlessCI --code-coverage // in 13.0.2, it will print messages below but it works well under angular v12.x // I'm not sure if something wrong I configured or just some break changes happened in v13.x :( =============================== Coverage summary =============================== Statements : Unknown% ( 0/0 ) Branches : Unknown% ( 0/0 ) Functions : Unknown% ( 0/0 ) Lines : Unknown% ( 0/0 ) ================================================================================
Author   simplejason
🌐
Compile N Run
compilenrun.com › angular tutorial › angular testing › angular code coverage
Angular Code Coverage | Compile N Run
Angular CLI projects come with built-in support for code coverage via Karma and Istanbul. Here's how to enable and configure it: To run your tests with coverage reporting, simply add the --code-coverage flag to the test command: