Some signs of having Integrated Tests are: • We spin up other services in a local testing environment • We test against other services in a shared testing environment • Changes to your system breaks tests for other systems https://labs.spotify.com/2018/01/11/testing-of-microservices/ @bsideup
As simple as PostgreSQLContainer postgresql = new PostgreSQLContainer() GenericContainer redis = new GenericContainer("redis:3") .withExposedPorts(6379) @bsideup
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @ContextConfiguration(initializers = Initializer.class) public abstract class AbstractIntegrationTest { @ClassRule public static GenericContainer redis = new GenericContainer("redis:3.0.6") .withExposedPorts(6379); @ClassRule public static MockServerContainer mockServer = new MockServerContainer(); } Still using all the Spring goodies! @bsideup
Takeaways • https://testcontainers.org • Works on Linux, Mac and Windows • …including CIs like Jenkins, Travis, CircleCI, GH Actions, Azure Pipelines, …
• Provides a great balance between flexibility, usability, speed and features @bsideup