I work on an angular application with 3000+ unit tests (93% code coverage for 40k lines), we use the angular testbed and we test against the HTML (although this wasn't always the case, it has been for the last 2000 tests or so). We've found them to be invaluable (which is why we spend time writing them) The trick for us was small components and proper separation of concerns. You mention needing to include modules "needed by other components" this suggests you are either intentionally writing integration tests (which we use protractor for) or you are incorrectly writing unit tests. If you are trying to write unit tests, everything that isn't the thing you are testing should be mocked in the unit test. If you are testing component A, you aren't concerned with what component B does (that is covered in component B's unit test) so you mock it. Proper mocking can help cut down on "I changed a thing in one component, now I need to update the tests in 40 places" (a mistake we've certainly made). To give you an idea, it takes me about an hour to unit test a medium sized component (~60 lines) to 100% coverage including HTML. Some of our older stuff, before we got pretty good at testing (200+ line components, poor separation of concerns) might take half a day. Some people mentioned cypress and other libraries, I've never tried them but I would argue this: separation of concerns, small components, and proper unit testing strategies are time savers regardless of the testing framework and whether or not you dump angular testbed you should strive to do these things in your code, you'll be glad you did. Answer from colton_neil on reddit.com
🌐
Infinum
infinum.com › handbook › frontend › angular › angular-guidelines-and-best-practices › testing
Frontend Handbook | Angular / Angular guidelines and best practices / Testing
If you want to run e2e tests on some specific environment instead of a local environment, you can run Protractor directly instead of via Angular CLI, simply by executing protractor (make sure to install it globally, use binary from node_modules, or create a script in package.json).
🌐
Testing-angular
testing-angular.com
Testing Angular – A Guide to Robust Angular Applications.
The Angular framework is a mature and comprehensive solution for enterprise-ready applications based on web technologies. At Angular’s core lies the ability to test all application parts in an automated way. How do we take advantage of Angular’s testability? This guide explains the principles of automated testing as well as the practice of testing Angular web applications.
Discussions

What are your Angular testing best practices?
I work on an angular application with 3000+ unit tests (93% code coverage for 40k lines), we use the angular testbed and we test against the HTML (although this wasn't always the case, it has been for the last 2000 tests or so). We've found them to be invaluable (which is why we spend time writing them) The trick for us was small components and proper separation of concerns. You mention needing to include modules "needed by other components" this suggests you are either intentionally writing integration tests (which we use protractor for) or you are incorrectly writing unit tests. If you are trying to write unit tests, everything that isn't the thing you are testing should be mocked in the unit test. If you are testing component A, you aren't concerned with what component B does (that is covered in component B's unit test) so you mock it. Proper mocking can help cut down on "I changed a thing in one component, now I need to update the tests in 40 places" (a mistake we've certainly made). To give you an idea, it takes me about an hour to unit test a medium sized component (~60 lines) to 100% coverage including HTML. Some of our older stuff, before we got pretty good at testing (200+ line components, poor separation of concerns) might take half a day. Some people mentioned cypress and other libraries, I've never tried them but I would argue this: separation of concerns, small components, and proper unit testing strategies are time savers regardless of the testing framework and whether or not you dump angular testbed you should strive to do these things in your code, you'll be glad you did. More on reddit.com
🌐 r/Angular2
24
25
December 3, 2020
Unit Testing in a New Angular Project - Best Library Recommendations?
Testing Library: https://testing-library.com/docs/angular-testing-library/intro/ Terrible name, great library More on reddit.com
🌐 r/Angular2
35
13
March 5, 2025
Best practices for testing with Angular
Playwright for e2e has been terrific. We haven't found unit tests to be especially useful. More on reddit.com
🌐 r/Angular2
10
18
May 19, 2023
Any good tools or practices to debug and track randomly failed angular unit tests
Angular is Google's open source framework for crafting high-quality front-end web applications. r/Angular2 exists to help spread news, discuss current developments and help solve problems. Welcome! ... Hi community, we are facing some randomly failed unit tests with Angular in the server that ... More on reddit.com
🌐 r/Angular2
1
3
October 10, 2022
🌐
DEV Community
dev.to › chintanonweb › mastering-angular-unit-testing-a-comprehensive-guide-with-examples-3eg9
Mastering Angular Unit Testing: A Comprehensive Guide with Examples - DEV Community
September 13, 2023 - In this article, we've explored the importance of unit testing in Angular development, discussed the setup of a testing environment, and provided an example of writing unit tests for an Angular component. We've also covered best practices and answered common questions to help you get started with Angular unit testing effectively.
🌐
Medium
medium.com › bb-tutorials-and-thoughts › angular-a-comprehensive-guide-to-unit-testing-with-angular-and-best-practices-e1f9ef752e4e
Angular — A Comprehensive guide to unit-testing with Angular and Best Practices | by Bhargav Bachina | Bachina Labs | Medium
May 30, 2020 - Let’s select an app.component.ts component from the above project and test it. Look at the spec file that angular CLI generated for us when we use the command ng n c . I added f (line 5) to describe global function to run only this file when we execute tests.
🌐
Andyshora
andyshora.com › unit-testing-best-practices-angularjs.html
Unit Testing Best Practices in AngularJS
(Always best to confirm its ok to skip these things first though, could be dangerous!) Let's go through some actual examples. describe("Unit Testing Examples", function() { beforeEach(angular.mock.module('App')); it('should have a LoginCtrl controller', function() { expect(App.LoginCtrl).toBeDefined(); }); it('should have a working LoginService service', inject(['LoginService', function(LoginService) { expect(LoginService.isValidEmail).not.to.equal(null); // test cases - testing for success var validEmails = [ 'test@test.com', 'test@test.co.uk', 'test734ltylytkliytkryety9ef@jb-fe.com' ]; // te
🌐
Reddit
reddit.com › r/angular2 › what are your angular testing best practices?
r/Angular2 on Reddit: What are your Angular testing best practices?
December 3, 2020 -

Writing tests that are checking the rendered HTML are a real pain and the worst productivity killer I've ever encountered! I mean tests with TestBed.createComponent and nativeElement.querySelector and the like.

Already the test setup is a pain, because you have to list all the modules even the ones that are not directly used but needed by other components. The compiler doesn't necessarily show this kind of error, because sometimes this will only lead to runtime errors. If a used component gets a new dependency, you have to change the test ...

Using TestBed is also incredibly slow. fixture.detectChanges, tick and the likes are not productivity boosters either.

Locating and interacting with elements is sometimes a pain, too. For example I've tested a view with expandable elements. First I selected the buttons to expand and then called click on them. But it worked only for a single one (no matter wich one). Maybe I made a mistake, but the details are not the point, the point is that it is so hard to write this kind of test.

So, how do you test your Angular application? What do you test at what level? What approach do you use on the different testing layers (e. g. unit tests without HTML, cypress, snapshots ...)?

Top answer
1 of 9
16
I work on an angular application with 3000+ unit tests (93% code coverage for 40k lines), we use the angular testbed and we test against the HTML (although this wasn't always the case, it has been for the last 2000 tests or so). We've found them to be invaluable (which is why we spend time writing them) The trick for us was small components and proper separation of concerns. You mention needing to include modules "needed by other components" this suggests you are either intentionally writing integration tests (which we use protractor for) or you are incorrectly writing unit tests. If you are trying to write unit tests, everything that isn't the thing you are testing should be mocked in the unit test. If you are testing component A, you aren't concerned with what component B does (that is covered in component B's unit test) so you mock it. Proper mocking can help cut down on "I changed a thing in one component, now I need to update the tests in 40 places" (a mistake we've certainly made). To give you an idea, it takes me about an hour to unit test a medium sized component (~60 lines) to 100% coverage including HTML. Some of our older stuff, before we got pretty good at testing (200+ line components, poor separation of concerns) might take half a day. Some people mentioned cypress and other libraries, I've never tried them but I would argue this: separation of concerns, small components, and proper unit testing strategies are time savers regardless of the testing framework and whether or not you dump angular testbed you should strive to do these things in your code, you'll be glad you did.
2 of 9
6
a test can manipulate the component state (especially when running in random order). so if you call the first fixture.detectChanges() in the "root" beforeEach, keep in mind that ngOnInit() has already been called when entering a sub-describe or it. in our current project coverage > speed, but we focus on unit tests create a helper function that does the whole TestBed.configureTestingModule() to aboid boilerplate Maybe use a dedicated Tool for e2e or integratipn tests, I like Katalon one expect() per it(), helps you finding problems a lot better access injected stuff with TestBed.inject if it has not to be mocked necessarily
🌐
Angular
v17.angular.io › guide › testing
Angular - Testing
The testing documentation offers tips and techniques for unit and integration testing Angular applications through a sample application created with the Angular CLI.
Find elsewhere
🌐
Angular
angular.dev › guide › testing
Testing • Overview • Angular
Vitest runs your unit tests in a Node.js environment. To simulate the browser's DOM, Vitest uses a library called jsdom. This allows for faster test execution by avoiding the overhead of launching a browser. You can swap jsdom for an alternative like happy-dom by installing it and uninstalling jsdom.
🌐
Gorillalogic
gorillalogic.com › home › technical › best practices for angular unit testing
Best Practices for Angular Unit Testing - We Build Digital Platform & Products accelerated by AI
July 28, 2023 - Instead of testing an application as a whole, we break it down into smaller units that are easier to test and to conceptualize. This allows us to check our code in a granular way and have a clear separation of concerns within each unit. The easiest way to separate these units is by individual file, be it an Angular service, component, pipe, etc.
🌐
Medium
medium.com › @manishasiram › angular-unit-testing-best-practices-28626049cf26
Angular unit Testing best practices | by Manisha Siram | Medium
September 13, 2023 - Isolate Units of Code: Ensure that your tests focus on testing individual units of code (components, services, directives) in isolation. Use mocks and stubs for dependencies to isolate the code being tested.
🌐
Medium
medium.com › @roshannavale7 › advanced-angular-testing-in-2025-best-practices-for-robust-unit-and-e2e-testing-1a7e629e000b
Advanced Angular Testing in 2025: Best Practices for Robust Unit and E2E Testing | by Roshan Navale | Medium
April 12, 2025 - Angular, as a popular frontend framework, offers powerful tools for both unit and end-to-end (E2E) testing. But merely having tools isn’t enough — it’s how you use them that determines the quality and maintainability of your test suite. ... In this blog, we’ll walk through best practices that can help you elevate your Angular testing game, focusing on unit testing with Jasmine and TestBed, and E2E testing using Cypress, which has now become the preferred choice over Protractor.
🌐
Empirical Edge Inc
empiricaledge.com › home › blog › testing angular applications: tools, best practices, and strategies
Testing Angular Applications: Tools, Best Practices, and Strategies
September 22, 2025 - The best tools and practices for testing Angular apps. Master unit, integration, and E2E tests with Jasmine, Karma, Protractor, and Jest.
🌐
Medium
medium.com › @rictorres.uyu › angular-unit-testing-best-practices-4e1d4d3d0b32
Angular Unit Testing: Best Practices | by Ricardo Torres | Medium
March 11, 2025 - Key advantages include: Early Defect Detection: Proactively identifying issues during development minimizes costly debugging later in the lifecycle. Enhanced Code Maintainability: Well-tested code is significantly easier to refactor, extend, ...
🌐
Angular Minds
angularminds.com › blog › writing-your-first-angular-unit-test-step-by-step-tutorial
Writing Your First Angular Unit Test: Step-by-Step Tutorial
March 19, 2024 - Unit testing in Angular is a very important practice for ensuring the dependable and estimated outcomes of Angular applications. By using the power of Jasmine and Karma, you can write multiple test cases, to test angular components and structures independently of each other, configure the testing environment with TestBed, and leverage mocking and spying to achieve independent and isolated execution. With karma and jasmine with best practices in hand, you can definitely validate your code’s functionality, enhance its testing workflow, and build robust Angular applications that meet AAA practices.
🌐
Tim Deschryver
timdeschryver.dev › blog › good-testing-practices-with-angular-testing-library
Good testing practices with 🦔 Angular Testing Library
To get started, the first step is to install @testing-library/angular, after that we're good to go. ... In this post, we'll take an introduction by writing tests for a feedback form, starting very simple and keep building on top of it. The form we'll put under test has a required name field, a required rating field that must be between 0 and 10, a summary field, and a select box to select a t-shirt size.
🌐
DEV Community
dev.to › this-is-angular › unit-testing-in-angular-170l
Mastering Angular Unit Testing: Best Practices and Tools - DEV Community
February 26, 2025 - The Angular Testing Library (ATL) was introduced as a valuable tool for component testing, mimicking user interactions as close as possible to real users. Additionally, the article mentioned useful tools like jest-auto-spies for efficient class mocking and provided resources for further exploration of testing practices in Angular.
🌐
BrowserStack
browserstack.com › home › guide › how to perform unit testing for angular apps?
How to perform Unit testing for Angular apps? | BrowserStack
May 7, 2025 - Step by Step tutorial to perform Unit Testing for Angular Apps using Jasmine and Karma. Learn to create, write and run Angular unit tests.
🌐
Gorillalogic
gorillalogic.com › blog › best-practices-for-angular-unit-testing
Best Practices for Angular Unit Testing
July 28, 2023 - Instead of testing an application as a whole, we break it down into smaller units that are easier to test and to conceptualize. This allows us to check our code in a granular way and have a clear separation of concerns within each unit. The easiest way to separate these units is by individual file, be it an Angular service, component, pipe, etc.
🌐
Angular
angular.dev › guide › testing › components-scenarios
Component testing scenarios • Angular
Injecting the real UserAuthentication could be difficult. The real service might ask the user for login credentials and attempt to reach an authentication server. These behaviors can be hard to intercept. Be aware that using test doubles makes the test behave differently from production so use them sparingly...
🌐
Reddit
reddit.com › r/angular2 › unit testing in a new angular project - best library recommendations?
r/Angular2 on Reddit: Unit Testing in a New Angular Project - Best Library Recommendations?
March 5, 2025 -

Hey r/Angular2!

I'm starting a brand new Angular project and I'm planning to implement unit tests from the very beginning. I'm looking for recommendations on the best unit testing library to use in this context.

I'm aware that Angular CLI sets up Jasmine and Karma by default, but I'm open to exploring other options if they offer significant advantages. I'm particularly interested in:

  • Ease of use and setup: I want a library that's relatively straightforward to integrate and use within an Angular project.

  • Maintainability and readability: Tests should be easy to write, understand, and maintain over time.

  • Integration with Angular features: Seamless compatibility with Angular's dependency injection, components, services, and other core features is crucial.

  • Performance: Fast test execution is important for a smooth development workflow.

  • Mocking capabilities: Effective mocking of dependencies is essential for isolating units of code.

  • Community support and documentation: A strong community and comprehensive documentation are valuable resources.

I've heard about Jest being a popular alternative to Karma/Jasmine, and I'm curious about its benefits in an Angular environment. Has anyone had experience using Jest with Angular and can share their thoughts?

Also, what are your thoughts on:

  • Using standalone components and the impact of the testing strategy.

  • Testing best practices for signal based applications.

  • Any tools to help with test coverage reporting outside of the standard Karma output.

  • Any libraries that help with testing angular forms and http requests. Are there any other libraries or tools that I should consider? Any advice or insights you can offer would be greatly appreciated!

Thanks in advance!