This document describes the component testing strategy using Spring Boot Test with TestContainers.
Component tests verify that major features work correctly in an integrated environment with real containers (PostgreSQL, Redis). This is similar to Arquillian's approach but uses Spring Boot Test, which is the standard for Spring Boot applications.
All component tests extend AbstractComponentTest, which provides:
- TestContainers Setup: PostgreSQL and Redis containers
- Spring Boot Test: Full application context loading
- Dynamic Properties: Automatic configuration of database and Redis connections
- Profile: Uses
component-testprofile for test-specific configuration
- Profile:
component-test - Configuration File:
application-component-test.yml - Containers:
- PostgreSQL 15 (alpine)
- Redis 7 (alpine)
- Container Reuse: Enabled for faster test execution
Tests the complete data polling workflow:
- Polling external APIs
- Saving to database
- Filtering with LLM (if applicable)
- Enqueuing to processing queue
- Duplicate detection
- Minimum value filtering
Key Assertions:
- Data items are persisted correctly
- Filtering service is called (if applicable)
- Accepted items are enqueued
- Duplicates are rejected
Tests Redis-based priority queue:
- Enqueue/dequeue operations
- Priority ordering (higher value = higher priority)
- Queue size tracking
- Empty queue handling
- Item removal from queue
Key Assertions:
- Higher value items dequeued first
- Queue size tracked correctly
- Operations are atomic
Tests LLM-based filtering service (if applicable):
- High-value item acceptance
- Low-value/complex item rejection
- Confidence threshold application
- Time threshold application
- Error handling
Key Assertions:
- LLM responses are parsed correctly
- Thresholds are applied
- Fail-safe behavior on errors
Tests Git repository operations (if applicable):
- Repository cloning
- URL parsing (various formats)
- Clone status checking
- Owner/name extraction
Key Assertions:
- Repositories clone successfully
- URL formats are handled correctly
- Status tracking works
Tests HTTP client integration:
- External API client
- Internal API client
- Error handling
- Rate limiting
Key Assertions:
- API responses are parsed correctly
- Errors are handled gracefully
- Rate limits are respected
- Docker must be running
- TestContainers will automatically pull and start containers
# Run all component tests
./gradlew test --tests "com.yourproject.component.*"
# Run specific test class
./gradlew test --tests "com.yourproject.component.DataPollingComponentTest"
# Run with verbose output
./gradlew test --tests "com.bugbounty.component.*" --info- TestContainers starts PostgreSQL and Redis containers
- Spring Boot Test loads full application context
- Dynamic properties configure connections to containers
- Tests execute against real containers
- Containers are cleaned up after tests
- Isolation: Each test should be independent
- Cleanup: Use
@BeforeEachto reset state - Mocking: Mock external services (LLM, APIs) when appropriate
- Assertions: Use AssertJ for fluent assertions
- Naming: Use descriptive test names with
@DisplayName
- Ensure Docker is running
- Check Docker daemon is accessible
- Verify sufficient resources (memory, disk)
- TestContainers uses random ports by default
- If issues occur, check for port conflicts
- Enable container reuse (already configured)
- Use
@Containerwithreuse = true - Consider parallel test execution
- Add more end-to-end scenarios
- Test error recovery scenarios
- Add performance/load tests
- Test concurrent operations
- Add contract tests for API clients