用Test Container做 Integration Test
Integration Test #
Integration test is to test whether many separately developed modules work together as expected.
narrow integration tests #
- exercise only that portion of the code in my service that talks to a separate service
- uses test doubles of those services, either in process or remote
- thus consist of many narrowly scoped tests, often no larger in scope than a unit test (and usually run with the same test framework that’s used for unit tests)
narrow integration tests are limited in scope, they often run very fast, so can run in early stages of a DeploymentPipeline, providing faster feedback should they go red.
broad integration tests #
- require live versions of all services, requiring substantial test environment and network access
- exercise code paths through all services, not just code responsible for interactions
Why Container Test #
https://www.testcontainers.org/ Test container allows you to combine the benefits of unit test with the benefits of containerization. It starts containers for you to run your Integration tests as a Unit Test.
- run integration test as early as possible
- practical and executable for every developer
- environment isolation ↔︎ limited in scope
What does it do #
- start a container
- init test case data
- start service
- run junit
- assert
Furthermore #
- Cover snapshot test
- Cover regression test