Building Integration Tests Similar to User Scenarios with TestContainers
Key point
Kurly used TestContainers to automate integration tests that closely resemble real environments, improving deployment stability.
Details
Kurly's Delivery Product Team introduced TestContainers to automate integration tests similar to the actual QA environment. Previously, unit tests per server and Mock-based integration tests made it difficult to detect bugs in advance caused by mismatched constraints between servers.
Limitations of Existing Testing Methods and the Solution
The existing approach performed tests by mocking external dependencies according to each server's concerns. However, if a change in the query conditions of the delivery management server did not match the data generation logic of the event collection server, individual tests could pass while an order exposure bug still occurred at the actual QA stage. To solve this, the team proposed an integration test structure that spins up real infrastructure such as Kafka, PostgreSQL, and Spring Application as Docker containers to verify the interworking flow between servers.
TestContainers-Based Integration Test Configuration
The test environment consists of 4 containers: KafkaContainer, PostgisContainer, ApiContainer, and ConsumerContainer. Communication between containers is set up via Network.newNetwork(), and internal connections are made by specifying service names with withNetworkAliases. The Spring Application pulls images from the deployment Container Registry, and withImagePullPolicy is applied to ensure the latest image is used each time the test runs.
Authentication Bypass and CI/CD Integration
To reduce the complexity of running an actual authentication server, an authentication bypass method using magic-token was applied in the Local profile environment. The test code publishes order events to Kafka and calls the API to verify that the data is retrieved correctly. This test is automatically run upon deployment completion via the workflow_run trigger in GitHub Actions, allowing QA personnel to focus on testing abnormal cases.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.