This document outlines the testing strategy, methodologies, and frameworks used in the ms-event-seating microservice.
- Testing Strategy
- Test Categories
- Testing Frameworks and Libraries
- Test Environment Configuration
- Integration Testing with TestContainers
- Mock Authentication and Authorization
- Test Coverage
- Running Tests
- CI/CD Integration
- Best Practices
The ms-event-seating microservice follows a comprehensive testing approach with multiple layers:
- Unit Testing: Testing individual components in isolation by mocking their dependencies.
- Integration Testing: Testing the interaction between components and external services using containerized dependencies.
- API Testing: Testing REST endpoints to ensure correct behavior, validation, and error handling.
The testing pyramid is followed, with more unit tests than integration tests, ensuring fast feedback cycles while still providing good coverage.
- Controller Tests: Verify REST controller behavior with mocked service dependencies
- Service Tests: Verify business logic in service layer
- Factory Tests: Ensure object creation logic works correctly
- Exception Tests: Validate exception handling
- API Integration Tests: End-to-end tests of REST endpoints with containerized dependencies
- Database Integration: Test JPA repositories against a real PostgreSQL database
- External Services: Test interactions with Redis, Kafka, and S3
The following testing libraries and frameworks are used:
| Library/Framework | Version | Purpose |
|---|---|---|
| JUnit 5 | Bundled with Spring Boot | Test framework |
| Mockito | 5.2.0 | Mocking dependencies |
| Spring Test | Bundled with Spring Boot | Testing Spring components |
| Spring Security Test | Bundled with Spring Boot | Authentication/authorization testing |
| TestContainers | Latest | Running containerized dependencies for tests |
| WireMock | 4.0.0-beta.15 | Mocking external HTTP APIs |
| H2 Database | Runtime | In-memory database for unit tests |
Tests are configured with a separate application configuration in src/test/resources/application.yml, which includes:
- H2 in-memory database for unit tests
- Disabled Redis caching
- Mock OAuth2 configurations
- Test-specific tier limits and application settings
The AbstractIntegrationTest class provides the foundation for integration tests with the following containerized dependencies:
- PostgreSQL: For database interaction testing
- Redis: For caching tests
- Kafka: For event processing tests
- Debezium: For CDC (Change Data Capture) testing
- LocalStack: For AWS S3 storage service testing
These containers are started before tests run and are configured dynamically in the Spring context through @DynamicPropertySource.
Authentication and authorization testing is handled through:
- Spring Security Test: For controller tests
- Custom JWT Mock: Using
WithMockJwtUserannotation for JWT authentication - WireMock: For mocking the OIDC server in integration tests
The JwtTestUtils class provides utility methods to generate test JWT tokens with various claims and roles.
Test coverage is monitored for the following areas:
- Controllers: Ensuring all endpoints handle various scenarios correctly
- Services: Verifying business logic for all operations
- Exception Handling: Testing appropriate exception responses
- Security: Validating authorization and authentication requirements
./mvnw test./mvnw test -Dtest=*IT./mvnw verifyTests are run automatically as part of the CI pipeline. The following test stages are included:
- Build and Unit Test: Run on every commit
- Integration Tests: Run on pull requests and main branch commits
- Test Reports: Generated and stored as artifacts
The following best practices are followed in the test code:
- Test Independence: Each test should be independent and not rely on other tests
- Clean Setup and Teardown: Tests should clean up after themselves
- Meaningful Test Names: Test methods are named to describe the behavior being tested
- Assertions: Use clear, specific assertions that fail with meaningful messages
- Test Data: Maintain test data separately from production code
- Mocking: Only mock what is necessary; prefer using test containers for external dependencies
- Test Configuration: Keep test configuration separate from production configuration
Potential areas for testing improvement:
- Property-Based Testing: Introduce property-based testing for edge cases
- Performance Testing: Add performance tests for critical paths
- Security Testing: Enhance security testing with more sophisticated scenarios
- Chaos Testing: Introduce chaos testing for resilience verification
This document is maintained by the Ticketly Engineering team. Last updated: October 12, 2025.