Integration Testing Guidelines
Integration tests are critical for ensuring that your FlowInquiry backend components work together correctly. This guide covers how to write effective integration tests using TestContainers in the FlowInquiry ecosystem.
Benefits of Using TestContainers
TestContainers 
- Realistic testing environment: Tests run against actual databases and services instead of mocks
- Consistency across environments: The same containers run in CI/CD pipelines and local development
- Isolation: Each test suite can use its own containerized dependencies
- Parallel test execution: TestContainers supports concurrent testing
- Simplified setup: No need to maintain external test infrastructure
- Comprehensive coverage: Test the full stack, including database interactions and external services
Writing Integration Tests in FlowInquiry
Test Data Management
FlowInquiry uses Liquibase for database migrations, which provides an elegant way to handle test data:
- Create migration scripts dedicated to test data in the
src/main/resources/db/changelog
directory - Add the
context="test"
attribute to changesets containing test data:
<changeSet id="create-test-users" author="developer" context="test">
<insert tableName="users">
<column name="id" value="test-user-1"/>
<column name="username" value="testuser"/>
<column name="email" value="test@example.com"/>
</insert>
</changeSet>
- These test changesets will only be applied during integration tests, keeping your development and production databases clean
Writing Integration Tests
To create an integration test in FlowInquiry:
- Create a test class in the
src/integration-test/java
directory - Annotate the class with
@IntegrationTest
:
@IntegrationTest
public class UserServiceIntegrationTest {
@Autowired
private UserService userService;
@Test
public void testFindUserById() {
User user = userService.findById("test-user-1");
assertNotNull(user);
assertEquals("testuser", user.getUsername());
}
}
The @IntegrationTest
annotation handles:
- Starting the required containers (PostgreSQL, Redis, etc.)
- Applying database migrations with test context
- Configuring Spring to use the containerized services
- Cleaning up after tests complete
Running Integration Tests
Running in IDE
To run integration tests in your IDE:
- Make sure you have Docker installed and running
- Right-click on the test class and select “Run as JUnit Test”
- If you want to debug, right-click and choose “Debug as JUnit Test”
Most popular IDEs (IntelliJ IDEA, Eclipse, VS Code) support running these tests directly.
Running with Gradle
To run integration tests using Gradle:
./gradlew integrationTest
This will:
- Start the required Docker containers
- Execute all tests annotated with
@IntegrationTest
- Generate test reports in the
build/reports/tests/integrationTest
directory - Shut down and clean up containers after completion
If you want to run a specific integration test class:
./gradlew integrationTest --tests "com.flowinquiry.backend.UserServiceIntegrationTest"