Testing Fundamentals

This section introduces the testing concepts and frameworks used in LightNap.

Unit Testing Overview

Unit testing in LightNap focuses on testing individual components, services, and utilities in isolation using Karma and Jasmine.

Unit Testing Concepts

  • Test Bed: Angular’s testing utility for configuring dependency injection
  • Fixtures: Component wrappers for testing DOM interactions
  • Spies: Mock functions to verify method calls
  • Async Testing: Handling observables, promises, and component lifecycle

Test Structure

describe('Component/Service Name', () => {
  beforeEach(() => {
    // Setup test environment
  });

  it('should behave correctly', () => {
    // Test implementation
  });
});

E2E Testing Overview

End-to-end testing validates complete user workflows using Cypress, simulating real user interactions in a browser.

E2E Testing Concepts

  • Test Runner: Interactive GUI for test development
  • Commands: Cypress API for browser automation
  • Assertions: Verify application state and behavior
  • Interception: Mock network requests for reliable testing

Test Flow

describe('User Workflow', () => {
  it('should complete full user journey', () => {
    cy.visit('/start');
    // User actions...
    cy.get('[data-cy="result"]').should('be.visible');
  });
});

Testing in LightNap’s Architecture

Layered Testing Approach

LightNap’s architecture supports testing at multiple levels:

  1. Core Services: Test business logic independently
  2. Components: Test UI behavior with mocked dependencies
  3. Integration: Test component and service interactions
  4. E2E: Test complete user scenarios

Shared Testing Infrastructure

The src/testing/ directory provides:

  • Builders: Factory functions for test data creation
  • Mocks: Pre-configured service mocks
  • Matchers: Custom Jasmine assertions
  • Test Module: Common testing configuration

CI/CD Integration

Tests run automatically in CI pipelines:

  • Unit Tests: Fast feedback on code changes
  • E2E Tests: Validate deployment readiness
  • Coverage Reports: Track testing completeness
  • Parallel Execution: Optimize CI performance

Getting Started with Testing

  1. Run Unit Tests: npm run test
  2. Run E2E Tests: npm run e2e:open
  3. Check Coverage: npm run test:coverage:open
  4. Debug Tests: Use browser dev tools or Cypress GUI

For detailed guides, see the Development Guide > Testing section.