← Back to Articles         
Angular Testing - Interview Questions

Angular Testing - Interview Questions

Published on 12 Oct 2026     3 min read Angular
Quick Revision

1. How do you test Angular components?

Use Angular TestBed and ComponentFixture to create component instances and verify their rendering, behavior, and interactions.

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

2. What is unit testing?

Unit testing verifies individual components, services, or functions independently. It uses mocks or stubs to isolate dependencies.

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

3. What is integration testing?

Integration testing verifies that multiple components or services work together correctly. For example, testing a component interacting with a service and reactive form.

4. How do you test Angular services?

Use TestBed.inject() to create or retrieve a service instance and verify its methods. Mock external dependencies such as HTTP services.

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

5. How do you test HTTP calls?

Use provideHttpClientTesting() and HttpTestingController to intercept HTTP requests and return mock responses without calling a real API.

const req = httpMock.expectOne('/api/users');
req.flush([{ id: 1, name: 'John' }]);

Key Point: Configure provideHttpClient() before provideHttpClientTesting().

6. How do you test route guards?

Test route guards by mocking authentication services and verifying whether navigation is allowed or redirected.

const result = TestBed.runInInjectionContext(() => authGuard(route, state));
expect(result).toBeTrue();

7. How do you test standalone components?

Import the standalone component directly into TestBed imports, instead of declaring it in an NgModule.

await TestBed.configureTestingModule({
  imports: [User]
}).compileComponents();

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

Use HttpTestingController to simulate JSON responses, HTTP errors, and status codes without accessing the actual ASP.NET Core Web API.

const req = httpMock.expectOne('/api/articles');
req.flush([{ id: 1, title: 'Angular Basics' }]);

9. What is end-to-end testing?

E2E testing verifies the complete application workflow through a browser, including navigation, forms, authentication, and API interactions.

Tools: Playwright and Cypress.

await page.goto('/login');
await expect(page.locator('h1')).toHaveText('Login');

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

Unit Testing

E2E Testing

Tests individual units

Tests complete workflows

Usually uses mocks

Uses a running application

Faster execution

Slower execution

Easier to isolate failures

Tests integration across layers

Example: Validate a service

Example: Login and navigate

 

Important Interview Revision Points

Concept

Key Point

Unit Testing

Tests individual functions or classes

Integration Testing

Tests combined components

E2E Testing

Tests complete user workflows

TestBed

Angular testing environment

ComponentFixture

Component testing wrapper

TestBed.inject()

Retrieves service instances

HttpTestingController

Mocks HTTP requests

provideHttpClientTesting()

Configures HTTP testing

Mocking

Replaces real dependencies

Spy

Tracks or replaces function calls

Jasmine

Testing framework

Vitest

Modern JavaScript testing framework

Playwright

Browser-based E2E testing

Cypress

E2E testing framework

Angular + ASP.NET Core Testing Flow

Angular Application
       |
       +-- Unit Tests
       |      |
       |      +-- Components
       |      +-- Services
       |      +-- Pipes / Guards
       |
       +-- Integration Tests
       |      |
       |      +-- Component + Service
       |      +-- Component + Form
       |
       +-- HTTP Tests
       |      |
       |      +-- Mock API Responses
       |
       +-- E2E Tests
              |
              +-- Browser
              +-- Angular Application
              +-- ASP.NET Core Web API
              +-- Test Database

Interview priority: Focus particularly on questions 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.

Key interview takeaway: Use TestBed for Angular unit testing, HttpTestingController for HTTP mocking, and Playwright or Cypress for E2E testing. Angular tests can validate frontend behavior without requiring the actual ASP.NET Core Web API.

← Back to Articles