This guide explains how to run tests in the streaming framework project.
The project separates tests into two categories:
- Unit Tests - Fast tests that don't require external dependencies (Redis)
- Integration Tests - Tests that require Redis and test real integrations
# Run all unit tests
./gradlew test
# Run tests for a specific module
./gradlew :core:test
./gradlew :aggregation:test
./gradlew :cdc:test# 1. Start Redis
docker-compose up -d
# 2. Run integration tests
./gradlew integrationTest
# 3. Stop Redis
docker-compose downThe project provides two test tasks:
test- Runs unit tests only (excludes@Tag("integration"))integrationTest- Runs integration tests only (includes@Tag("integration"))check- Runs both unit and integration tests
Tests are organized using JUnit 5 tags:
- Unit tests: No tag (default)
- Integration tests:
@Tag("integration")
Example integration test:
@Tag("integration")
public class RedisRegistryIntegrationExample {
@Test
public void testServiceRegistryAndDiscovery() throws Exception {
// Test code that requires Redis
}
}The project includes a docker-compose.yml file for test infrastructure:
# Start services
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f redis
# Stop services
docker-compose down
# Stop and remove volumes
docker-compose down -vIntegration tests use the REDIS_URL environment variable:
# Default
redis://127.0.0.1:6379
# Custom Redis
export REDIS_URL=redis://custom-host:6379
./gradlew integrationTest# Quick feedback - run unit tests only
./gradlew test --parallel# Run all tests to ensure nothing is broken
docker-compose up -d
./gradlew clean check
docker-compose down# Test specific module (unit tests)
./gradlew :core:test
# Test specific module (integration tests)
docker-compose up -d
./gradlew :core:integrationTest
docker-compose down# Run specific unit test class
./gradlew :core:test --tests "MessageTest"
# Run specific integration test
docker-compose up -d
./gradlew :core:integrationTest --tests "RedisRegistryIntegrationExample"
docker-compose down# Run with info level logging
./gradlew test --info
# Run with debug logging
./gradlew test --debug
# Show standard output
./gradlew test --console=plainname: Tests
on: [push, pull_request]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
- name: Run unit tests
run: ./gradlew test --parallel
integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
- name: Start Redis
run: docker-compose up -d
- name: Run integration tests
run: ./gradlew integrationTest
- name: Stop Redis
run: docker-compose downstreaming/
├── core/
│ └── src/test/java/
│ ├── *Test.java # Unit tests
│ └── *IntegrationExample.java # Integration tests (@Tag("integration"))
├── aggregation/
│ └── src/test/java/
│ ├── *Test.java # Unit tests
│ └── *IntegrationExample.java # Integration tests (@Tag("integration"))
└── docker-compose.yml # Test infrastructure
Run tests with coverage reports (requires JaCoCo plugin):
./gradlew test jacocoTestReport
# View report
open build/reports/jacoco/test/html/index.htmlProblem: Integration tests can't connect to Redis.
Solution:
# Make sure Redis is running
docker-compose ps
# Check Redis health
docker exec streaming-redis-test redis-cli ping
# Should return: PONG
# Restart Redis if needed
docker-compose restart redisProblem: Integration tests run during ./gradlew test.
Solution: Make sure integration test classes have @Tag("integration") annotation:
@Tag("integration")
public class MyIntegrationTest {
// ...
}Problem: ./gradlew command fails.
Solution:
# Regenerate wrapper
gradle wrapper --gradle-version 8.5
# Make executable
chmod +x gradlew- Keep unit tests fast - Mock external dependencies
- Make integration tests reliable - Use docker-compose for consistent environment
- Clean up after integration tests - Stop containers when done
- Run unit tests frequently - They're fast and don't need setup
- Run integration tests before commits - Catch integration issues early
- Use tags consistently - All integration tests should have
@Tag("integration")
- Contains registry and MQ integration tests
- Requires Redis for integration tests
- Most critical for integration testing
- Tests PV counter and Top-K analyzer
- Integration tests verify Redis sorted set operations
- Integration tests require external databases (disabled by default)
- Use
@Disabledannotation for tests requiring complex setup
- File-based tests don't require Redis
- Some integration tests may need additional services