Testing

Azu provides comprehensive testing support for building reliable web applications. This section covers unit testing, integration testing, and WebSocket testing strategies.

Overview

Azu's testing features are designed for:

  • Unit testing individual components and endpoints

  • Integration testing complete request-response cycles

  • WebSocket testing real-time communication flows

  • Test-driven development with fast feedback loops

  • Continuous integration with automated test suites

Testing Architecture

Key Testing Features

1. Unit Testing

  • Isolated component testing

  • Mock and stub support

  • Fast execution times

  • Comprehensive coverage

2. Integration Testing

  • Full request-response testing

  • Database integration

  • Template rendering tests

  • Middleware testing

3. WebSocket Testing

  • Channel behavior testing

  • Real-time event testing

  • Connection lifecycle testing

  • Message broadcasting tests

Quick Start

Basic Endpoint Test

Request Contract Test

WebSocket Channel Test

Unit Testing

Unit testing focuses on testing individual components in isolation:

Endpoint Testing

  • Test endpoint logic without HTTP overhead

  • Mock dependencies and external services

  • Test error handling and edge cases

  • Verify response format and content

Component Testing

  • Test live component behavior

  • Verify event handling

  • Test DOM updates and state changes

  • Mock WebSocket connections

Request/Response Testing

  • Test request validation logic

  • Verify response serialization

  • Test error scenarios

  • Validate data transformations

Learn more about Unit Testing →

Integration Testing

Integration testing verifies that components work together correctly:

HTTP Testing

  • Test complete request-response cycles

  • Verify middleware behavior

  • Test routing and parameter handling

  • Validate response headers and status codes

Database Testing

  • Test database interactions

  • Use test databases and fixtures

  • Test transaction handling

  • Verify data persistence

Template Testing

  • Test template rendering

  • Verify data binding

  • Test template inheritance

  • Validate output format

Learn more about Integration Testing →

WebSocket Testing

WebSocket testing focuses on real-time communication:

Channel Testing

  • Test connection lifecycle

  • Verify message handling

  • Test broadcasting behavior

  • Validate error handling

Spark Testing

  • Test client-side JavaScript

  • Verify DOM updates

  • Test event handling

  • Validate real-time synchronization

Real-time Testing

  • Test end-to-end real-time flows

  • Verify component updates

  • Test concurrent connections

  • Validate performance under load

Learn more about WebSocket Testing →

Test Organization

Directory Structure

Test Naming Conventions

  • Use descriptive test names

  • Group related tests with describe blocks

  • Use context blocks for different scenarios

  • Follow the pattern: describe ClassName do

Test Data Management

Mocking and Stubbing

Mock External Services

Mock WebSocket Connections

Test Configuration

Environment Setup

Database Testing

Continuous Integration

GitHub Actions

Test Coverage

Best Practices

1. Test Organization

  • Group related tests together

  • Use descriptive test names

  • Keep tests focused and single-purpose

  • Use setup and teardown appropriately

2. Test Data

  • Use factories for test data

  • Keep test data minimal and focused

  • Use realistic but simple data

  • Clean up test data after tests

3. Mocking Strategy

  • Mock external dependencies

  • Don't mock the code under test

  • Use mocks to isolate units

  • Verify mock interactions

4. Performance

  • Keep tests fast

  • Use parallel test execution

  • Avoid slow operations in tests

  • Use test databases for database tests

Next Steps

Examples

Check out the spec directory for complete working examples of:

  • Endpoint testing patterns

  • Component testing strategies

  • WebSocket testing approaches

  • Integration test scenarios


Ready to write tests? Start with Unit Testing to test individual components, then explore Integration Testing for testing component interactions.

Last updated

Was this helpful?