Testing Philosophy
The project implements:- Test-Driven Development (TDD): Tests are written before or alongside implementation
- Multi-Level Testing: Unit, integration, and end-to-end tests
- High Coverage: Target of 70%+ code coverage
- Clean Tests: Tests follow SOLID principles and are maintainable
Test Organization
Tests are organized by architectural layer, mirroring the source code structure:Running Tests
Test Coverage
Viewing Coverage Reports
After running tests with coverage, open the HTML report:Coverage Configuration
The project uses JaCoCo for coverage analysis, configured inbuild.gradle:
- Application entry point (
KitchenServiceApplication) - Configuration classes
- Spring Data JPA repositories (framework-generated code)
Coverage Metrics
| Category | Tests | Coverage |
|---|---|---|
| Domain Layer | 15 tests | 85%+ |
| Application Layer | 8 tests | 80%+ |
| Infrastructure Layer | 21 tests | 65%+ |
| Integration Tests | 22 tests | Full API coverage |
Test Types
Unit Tests
Unit tests verify individual components in isolation using mocks. Example: Command Test- Fast execution
- No external dependencies
- Tests single responsibility
- Uses mocks for dependencies
Integration Tests
Integration tests verify component interactions with real infrastructure. Example: Use Case Test- Tests component collaboration
- Uses Spring test context
- May use in-memory database (H2)
- Verifies integration points
End-to-End Tests
E2E tests verify complete API workflows. Example: API Integration Test- Tests full request/response cycle
- Uses real Spring Boot context
- Validates JSON serialization
- Tests HTTP status codes and headers
Testing Best Practices
Test Naming Convention
Tests follow a consistent naming pattern:Test Structure (Given-When-Then)
All tests follow the Given-When-Then pattern:Mocking Strategy
The project uses Mockito for mocking:- Mock: External dependencies (repositories, services)
- Real: Domain objects and value objects
- Spy: When partial mocking is needed
Continuous Integration
The project includes a GitHub Actions workflow (.github/workflows/ci.yml) that:
- Runs all tests on every push and pull request
- Generates coverage reports
- Fails the build if coverage drops below 70%
- Publishes test artifacts
Debugging Tests
Running Tests in Debug Mode
IntelliJ IDEA:- Right-click on test class or method
- Select “Debug ‘[TestName]’”
- Set breakpoints as needed
- Install Java Test Runner extension
- Click the debug icon next to the test
- Use built-in debugger
Viewing Test Output
Detailed test results are available in:- Test execution time
- Pass/fail status
- Failure stack traces
- Standard output/error
Next Steps
- Learn how to run locally
- Explore Docker setup
- Review the Architecture Overview
- Check the API Reference