Overview
Angular CLI projects use Karma as the default test runner, paired with Jasmine as the testing framework. Test files follow the*.spec.ts naming convention and are co-located with the source files they test.
When you run ng test, Karma launches a browser, compiles all *.spec.ts files, and reports results both in the terminal and in the browser window.
Running unit tests
ng test), Karma re-runs affected tests automatically whenever you save a source file. This is the recommended mode during active development.
When --code-coverage is passed, a coverage report is generated in the coverage/ directory. Open coverage/index.html in a browser to explore which lines, branches, and functions are covered.
Writing unit tests
Angular providesTestBed for configuring test modules and ComponentFixture for interacting with components in isolation.
fakeAsync and tick utilities, or async/await with fixture.whenStable().
End-to-end tests
End-to-end (E2E) tests simulate real user interactions across the full application stack.Angular CLI does not include an E2E framework by default. You must install and configure a framework such as Cypress or Playwright separately before
ng e2e will work. Follow the setup instructions for your chosen framework to register it as the E2E builder in angular.json.