World ◦ Modern [micro]service works with a lot of other services ◦ Points of integration are sources of failures • Isolation. Errors from other services don’t affect a system under test. ◦ In system tests it takes more time to understand a root cause
verification. Other services are under control. • Find issues before deployment • Can be used on a developer machine ◦ Sometimes it’s too hard to run System Tests on a developer machine
Provision embedded services from tests • Use VM/Vagrant Disadvantages • Dev machine pollution • Hard to run/manage/cleanup tests on CI especially in parallel
different tests are isolated ◦ Containers use random ports on a host machine ◦ Tests can be started on the same machine in parallel without port conflicts • Cleanup containers on JVM shutdown ◦ CI servers are always in a predictable state • Hides verbose container management commands behind developer friendly tools (Java code)
database container ◦ Configure a repository datasource ◦ Test repository methods • Integration tests ◦ Start dependent services in containers ◦ Configure a service under test ◦ Test the service API • UI/Acceptance tests ◦ Provision whole System ◦ Test an application using UI/Acceptance tools
new GenericContainer("redis:3") .withExposedPorts(6379); Then redis.getContainerIpAddress() redis.getMappedPort(6379) returns a binded random port on localhost