Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
Prague, 19-20 October 2017
TestContainers
@antonarhipov
Integration testing without the hassle
Why integration testing?
1. # of tests per time unit
1. # of tests per time unit
2. Complex setup
1. Reproducible environment
1. Reproducible environment
2. Both for development and CI
1. Reproducible environment
2. Both for development and CI
3. Isolated
1. Reproducible environment
2. Both for development and CI
3. Isolated
4. As real as possible
1. Reproducible environment
2. Both for development and CI
3. Isolated
4. As real as possible
5. Cross-platform
1. Reproducible environment
2. Both for development and CI
3. Isolated
4. As real as possible
5. Cross-platform
6. Easy to...
TestContainers to the rescue!
How does it work?
https://github.com/docker-java/docker-java
Docker environment discovery
Will start docker machine if it’...
GenericContainer redis =
new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
GenericContainer redis =
new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
PostgreSQLContainer postgreSQLContai...
TestContainers
https://github.com/testcontainers/testcontainers-java
Microservices!11
REST service
Java, Spring Boot
Redis & PostgreSQL
Calls to some other application
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class,
webEnvironment = WebEnvironment.R...
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class,
webEnvironment = WebEnvironment.R...
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class,
webEnvironment = WebEnvironment.R...
public class MockServerContainer<SELF extends MockServerContainer<SELF>>
extends GenericContainer<SELF> {
public MockServe...
public class MockServerContainer<SELF extends MockServerContainer<SELF>>
extends GenericContainer<SELF> {
public MockServe...
MockServerClient client = …
client.when(
HttpRequest.request("/analytics/issues/" +
project.projectId + "/app").withMethod...
How to test Java agents?
https://github.com/bsideup/javaagent-boilerplate
https://www.testcontainers.org
https://twitter.com/testcontainers
https://github.com/testcontainers
https://testcontainers...
anton@zeroturnaround.com
@antonarhipov
slideshare.net/arhan
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
Próxima SlideShare
Cargando en…5
×

GeeCON Prague 2017 - TestContainers

TestContainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

  • Inicia sesión para ver los comentarios

  • Sé el primero en recomendar esto

GeeCON Prague 2017 - TestContainers

  1. 1. Prague, 19-20 October 2017 TestContainers @antonarhipov Integration testing without the hassle
  2. 2. Why integration testing?
  3. 3. 1. # of tests per time unit
  4. 4. 1. # of tests per time unit 2. Complex setup
  5. 5. 1. Reproducible environment
  6. 6. 1. Reproducible environment 2. Both for development and CI
  7. 7. 1. Reproducible environment 2. Both for development and CI 3. Isolated
  8. 8. 1. Reproducible environment 2. Both for development and CI 3. Isolated 4. As real as possible
  9. 9. 1. Reproducible environment 2. Both for development and CI 3. Isolated 4. As real as possible 5. Cross-platform
  10. 10. 1. Reproducible environment 2. Both for development and CI 3. Isolated 4. As real as possible 5. Cross-platform 6. Easy to set up, use & maintain
  11. 11. TestContainers to the rescue!
  12. 12. How does it work? https://github.com/docker-java/docker-java Docker environment discovery Will start docker machine if it’s not started yet Containers cleanup on JVM shutdown
  13. 13. GenericContainer redis = new GenericContainer("redis:3.0.6") .withExposedPorts(6379);
  14. 14. GenericContainer redis = new GenericContainer("redis:3.0.6") .withExposedPorts(6379); PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:9.6.2") .withUsername(POSTGRES_USERNAME) .withPassword(POSTGRES_PASSWORD);
  15. 15. TestContainers https://github.com/testcontainers/testcontainers-java
  16. 16. Microservices!11 REST service Java, Spring Boot Redis & PostgreSQL Calls to some other application
  17. 17. @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class) public abstract class AbstractIntegrationTest { @ClassRule public static PostgreSQLContainer postgreSql = new PostgreSQLContainer(); @ClassRule public static GenericContainer redis = new GenericContainer("redis:3.0.6") .withExposedPorts(6379); @ClassRule public static MockServerContainer mockServer = new MockServerContainer();
  18. 18. @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class) public abstract class AbstractIntegrationTest { @ClassRule public static PostgreSQLContainer postgreSql = new PostgreSQLContainer(); @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!
  19. 19. @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class) public abstract class AbstractIntegrationTest { @ClassRule public static PostgreSQLContainer postgreSql = new PostgreSQLContainer(); @ClassRule public static GenericContainer redis = new GenericContainer("redis:3.0.6") .withExposedPorts(6379); @ClassRule public static MockServerContainer mockServer = new MockServerContainer(); External dependencies
  20. 20. public class MockServerContainer<SELF extends MockServerContainer<SELF>> extends GenericContainer<SELF> { public MockServerContainer() { super("jamesdbloom/mockserver:latest"); addExposedPorts(8080); } private MockServerClient client; @Override protected void containerIsStarted(InspectContainerResponse containerInfo) { super.containerIsStarted(containerInfo); client = new MockServerClient(getContainerIpAddress(), getMappedPort(getExposedPorts().get(0))); } }
  21. 21. public class MockServerContainer<SELF extends MockServerContainer<SELF>> extends GenericContainer<SELF> { public MockServerContainer() { super("jamesdbloom/mockserver:latest"); addExposedPorts(8080); } private MockServerClient client; @Override protected void containerIsStarted(InspectContainerResponse containerInfo) { super.containerIsStarted(containerInfo); client = new MockServerClient(getContainerIpAddress(), getMappedPort(getExposedPorts().get(0))); } }
  22. 22. MockServerClient client = … client.when( HttpRequest.request("/analytics/issues/" + project.projectId + "/app").withMethod("GET"), Times.unlimited()) .respond(singleIssueResponse());
  23. 23. How to test Java agents?
  24. 24. https://github.com/bsideup/javaagent-boilerplate
  25. 25. https://www.testcontainers.org https://twitter.com/testcontainers https://github.com/testcontainers https://testcontainers.slack.com
  26. 26. anton@zeroturnaround.com @antonarhipov slideshare.net/arhan

×