← Back to Articles         
Angular Testing

Angular Testing

Published on 02 Oct 2026     3 min read Angular
Testing

Angular Testing — Interview Quick Revision

1. How do you test Angular components?

Angular components are tested by creating them in a test environment, checking their properties/methods, triggering events, and verifying the rendered DOM. Angular provides TestBed for configuring component tests.

const fixture = TestBed.createComponent(ProductList);
expect(fixture.componentInstance).toBeTruthy();

Key point: Test both component logic and important template behavior.


2. What is unit testing?

Unit testing tests a small piece of code, such as a component, service, pipe, guard, or function, independently from the rest of the application. Dependencies are usually mocked or replaced with test doubles.

expect(service.calculateTotal(10, 2)).toBe(20);

Key point: Unit tests should be fast, isolated, and repeatable.


3. What is integration testing?

Integration testing verifies that multiple parts of the application work correctly together, such as a component interacting with a service or router.

Component → Service → Mock HTTP layer

Unlike a unit test, it tests the interaction between multiple units, while usually avoiding real external systems.


4. How do you test Angular services?

Create or inject the service using TestBed, then call its methods and verify the expected result. Any dependencies of the service can be mocked.

const service = TestBed.inject(ProductService);
expect(service).toBeTruthy();

For services using HttpClient, normally mock the HTTP layer instead of calling a real API.


5. How do you test HTTP calls?

Use Angular's HTTP testing support with provideHttpClientTesting() and HttpTestingController. It lets you verify the URL, HTTP method, request data, and return a fake response.

const req = httpMock.expectOne('/api/products');
expect(req.request.method).toBe('GET');
req.flush(mockProducts);

Older Angular: commonly configured using HttpClientTestingModule.


6. How do you test route guards?

Call the route guard with mocked authentication/authorization dependencies and verify whether it allows navigation or returns a UrlTree/redirect.

expect(result).toBeTrue();

For a functional guard, configure its dependencies with TestBed and execute it inside an injection context when required.


7. How do you test standalone components?

Standalone components can be added directly to the imports array of TestBed; they do not require an NgModule.

TestBed.configureTestingModule({
  imports: [ProductList]
});

Before standalone: components were normally declared through an NgModule or the test module's declarations.


8. How do you mock an ASP.NET Core API response?

Angular tests should normally not call the real ASP.NET Core API. Intercept the HTTP request using HttpTestingController and return mock JSON matching the backend DTO.

req.flush({ id: 1, name: 'Laptop', price: 50000 });

This allows Angular tests to run independently of ASP.NET Core and SQL Server.


9. What is end-to-end testing?

End-to-end (E2E) testing tests the application from the user's perspective through the complete workflow, such as Login → Products → Add Product → Logout.

Browser → Angular → ASP.NET Core API → Database

Tools such as Playwright or Cypress can automate browser-based E2E tests.


10. Unit testing vs E2E testing — what is the difference?

Unit Testing E2E Testing
Tests a small unit Tests a complete workflow
Dependencies usually mocked Multiple real/integrated layers involved
Fast Generally slower
Finds logic-level problems Finds system/integration problems
Example: test ProductService Example: test complete product creation

Interview answer: Unit testing checks individual components/services in isolation, while E2E testing verifies that the whole application workflow works from the user's perspective.

← Back to Articles