Integration Testing

Comprehensive guide to integration testing in Azu applications, focusing on testing component interactions and end-to-end workflows.

Overview

Integration testing verifies that different components of your Azu application work together correctly. This guide covers testing complete request-response cycles, database interactions, and multi-step workflows.

Integration Test Setup

Test Environment Configuration

# spec/integration/spec_helper.cr
require "../spec_helper"

# Integration test configuration
CONFIG.integration = {
  database_url: "postgresql://localhost/azu_integration_test",
  redis_url: "redis://localhost:6379/1",
  environment: "integration"
}

# Integration test utilities
module IntegrationHelpers
  def self.setup_test_database
    # Create test database schema
    DB.connect(CONFIG.integration.database_url) do |db|
      db.exec("CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name VARCHAR, email VARCHAR)")
      db.exec("CREATE TABLE IF NOT EXISTS posts (id SERIAL PRIMARY KEY, title VARCHAR, user_id INTEGER)")
    end
  end

  def self.cleanup_test_database
    # Clean test data
    DB.connect(CONFIG.integration.database_url) do |db|
      db.exec("TRUNCATE TABLE posts CASCADE")
      db.exec("TRUNCATE TABLE users CASCADE")
    end
  end

  def self.create_test_app
    # Create test application instance
    ExampleApp.new([
      Azu::Handler::Rescuer.new,
      Azu::Handler::Logger.new,
      Azu::Handler::CORS.new
    ])
  end
end

Test Application Setup

End-to-End Testing

Complete Request-Response Testing

Multi-Step Workflow Testing

Database Integration Testing

Database Transaction Testing

Database Relationship Testing

API Integration Testing

RESTful API Testing

API Error Handling Testing

Authentication Integration Testing

Session Management Testing

JWT Token Testing

File Upload Integration Testing

Multipart File Upload Testing

Cache Integration Testing

Redis Cache Testing

Background Job Integration Testing

Job Queue Testing

Performance Integration Testing

Load Testing Integration

Test Data Management

Test Data Setup

Test Isolation

Running Integration Tests

Test Commands

CI/CD Integration

Best Practices

1. Test Realistic Scenarios

2. Test Error Scenarios

3. Test Performance Boundaries

Next Steps


Integration tests ensure that your components work together correctly and catch issues that unit tests might miss.

Last updated

Was this helpful?