Testing Angular: Unit, Integration, and E2E (What to Test)
A practical testing strategy for Angular apps, from components to API flows.
Testing is not about writing tests everywhere. It’s about protecting the parts that break most often. ## Three levels of tests ### 1) Unit tests Test small logic: - pipes - pure functions - simple services Fast, cheap, lots of coverage. ### 2) Integration tests Test components with their dependencies: - component + template rendering - form validation - service calls mocked Great value for Angular apps. ### 3) End-to-end (E2E) tests Test full user workflows: - login flow - checkout flow - critical navigation Slower, but catches real-world breakage. ## A smart rule - Unit test logic-heavy code - Integration test key UI flows - E2E test only the top 5 most critical business journeys ## Testing pyramid picture ```mermaid flowchart TD A[E2E: Few] B[Integration: Some] --> A C[Unit: Many] --> B ``` > Next: Component unit testing basics using TestBed and mocking services.