SlideShare a Scribd company logo
TestContainers
Integration testing without the hassle
Anton Arhipov
@antonarhipov
Why integration testing?
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
1. # of tests per time unit
1. # of tests per time unit
2. Complex setup
JavaDay Kiev 2017 - Integration testing with TestContainers
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 set up, use & maintain
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
TestContainers to the rescue!
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
GenericContainer redis =
new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
GenericContainer redis =
new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
PostgreSQLContainer postgreSQLContainer =
new PostgreSQLContainer("postgres:9.6.2")
.withUsername(POSTGRES_USERNAME)
.withPassword(POSTGRES_PASSWORD);
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.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();
@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!
@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
JavaDay Kiev 2017 - Integration testing with TestContainers
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)));
}
}
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)));
}
}
MockServerClient client = …
client.when(
HttpRequest.request("/analytics/issues/" +
project.projectId + "/app").withMethod("GET"),
Times.unlimited())
.respond(singleIssueResponse());
https://github.com/bsideup/testcontainers-microservices-example
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
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.slack.com
anton@zeroturnaround.com
@antonarhipov
slideshare.net/arhan

More Related Content

PDF
GeeCON Prague 2017 - TestContainers
PDF
JavaOne 2017 - TestContainers: integration testing without the hassle
PDF
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
PPTX
Madrid JAM limitaciones - dificultades
PDF
Jenkins 2.0 最新事情 〜Make Jenkins Great Again〜
PPTX
Michal Kordas "Docker: Good, Bad or Both"
PDF
Супер быстрая автоматизация тестирования на iOS
PPTX
Shestakov Illia "The Sandbox Theory"
GeeCON Prague 2017 - TestContainers
JavaOne 2017 - TestContainers: integration testing without the hassle
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
Madrid JAM limitaciones - dificultades
Jenkins 2.0 最新事情 〜Make Jenkins Great Again〜
Michal Kordas "Docker: Good, Bad or Both"
Супер быстрая автоматизация тестирования на iOS
Shestakov Illia "The Sandbox Theory"

What's hot (20)

PDF
Testing the Enterprise layers, with Arquillian
PDF
Docker In the Bank
PDF
Docker In Bank Unrated
PDF
Everything as a code
PDF
Prow, ChatOps for open source projects
DOCX
Manoj Kolhe - Setup GitHub with Jenkins on Amazon Cloud - End-to-end Automation
PDF
Service Discovery. Spring Cloud Internals
PPTX
Capistrano与jenkins(hudson)在java web项目中的实践
PDF
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
PDF
Trust, but verify | Testing with Docker Containers
PDF
Continous Delivering a PHP application
PDF
One commit, one release. Continuously delivering a Symfony project.
PDF
手把手帶你學 Docker 入門篇
PDF
Devoxx 17 - Swift server-side
PDF
Docker con osdk_ver1.0
PDF
Docker 進階實務班
PDF
手把手帶你學Docker 03042017
PDF
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
PDF
Docker 初探,實驗室中的運貨鯨
Testing the Enterprise layers, with Arquillian
Docker In the Bank
Docker In Bank Unrated
Everything as a code
Prow, ChatOps for open source projects
Manoj Kolhe - Setup GitHub with Jenkins on Amazon Cloud - End-to-end Automation
Service Discovery. Spring Cloud Internals
Capistrano与jenkins(hudson)在java web项目中的实践
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Trust, but verify | Testing with Docker Containers
Continous Delivering a PHP application
One commit, one release. Continuously delivering a Symfony project.
手把手帶你學 Docker 入門篇
Devoxx 17 - Swift server-side
Docker con osdk_ver1.0
Docker 進階實務班
手把手帶你學Docker 03042017
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
Docker 初探,實驗室中的運貨鯨
Ad

Similar to JavaDay Kiev 2017 - Integration testing with TestContainers (20)

PDF
Stop Being Lazy and Test Your Software
PPTX
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)
PDF
Securing Containers, One Patch at a Time - Michael Crosby, Docker
PPTX
Codecamp 2020 microservices made easy workshop
PDF
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
PDF
Continuous Everything v2.0
PPTX
How to Achieve Canary Deployment on Kubernetes
PDF
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
PDF
Containerised Testing at Demonware : PyCon Ireland 2016
PDF
Continuous Everything
PDF
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
PPTX
Containerize your Blackbox tests
PDF
Cloud Native Dünyada CI/CD
PDF
Release Automation: Better Quality, Faster Deployment, Amazing ROI
PDF
Testing Automaton - CFSummit 2016
PDF
Testing automaton
PPTX
Run & Report
PDF
The Future of Security and Productivity in Our Newly Remote World
PPTX
Test it! Unit, mocking and in-container Meet Arquillian!
PDF
Gr8conf EU 2013 Speed up your development: GroovyServ and Grails Improx Plugin
Stop Being Lazy and Test Your Software
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)
Securing Containers, One Patch at a Time - Michael Crosby, Docker
Codecamp 2020 microservices made easy workshop
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Continuous Everything v2.0
How to Achieve Canary Deployment on Kubernetes
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Containerised Testing at Demonware : PyCon Ireland 2016
Continuous Everything
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Containerize your Blackbox tests
Cloud Native Dünyada CI/CD
Release Automation: Better Quality, Faster Deployment, Amazing ROI
Testing Automaton - CFSummit 2016
Testing automaton
Run & Report
The Future of Security and Productivity in Our Newly Remote World
Test it! Unit, mocking and in-container Meet Arquillian!
Gr8conf EU 2013 Speed up your development: GroovyServ and Grails Improx Plugin
Ad

More from Anton Arhipov (20)

PDF
JavaZone 2022 - Building Kotlin DSL.pdf
PDF
Idiomatic kotlin
PDF
TechTrain 2019 - (Не)адекватное техническое интервью
PDF
Build pipelines with TeamCity
PDF
Build pipelines with TeamCity
PDF
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
PDF
GeeCON Prague 2018 - Kotlin DSL in under an hour
PDF
Build pipelines with TeamCity and Kotlin DSL
PDF
Build pipelines with TeamCity
PDF
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
PDF
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
PDF
JUG.ua 20170225 - Java bytecode instrumentation
PDF
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
PDF
GeeCON 2017 - TestContainers. Integration testing without the hassle
PDF
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
PDF
JEEConf 2017 - Having fun with Javassist
PDF
Devclub 01/2017 - (Не)адекватное Java-интервью
PDF
Joker 2016 - Bytecode 101
PDF
JPoint 2016 - Etudes of DIY Java profiler
PDF
JPoint 2016 - Bytecode
JavaZone 2022 - Building Kotlin DSL.pdf
Idiomatic kotlin
TechTrain 2019 - (Не)адекватное техническое интервью
Build pipelines with TeamCity
Build pipelines with TeamCity
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
GeeCON Prague 2018 - Kotlin DSL in under an hour
Build pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
JUG.ua 20170225 - Java bytecode instrumentation
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
GeeCON 2017 - TestContainers. Integration testing without the hassle
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - Having fun with Javassist
Devclub 01/2017 - (Не)адекватное Java-интервью
Joker 2016 - Bytecode 101
JPoint 2016 - Etudes of DIY Java profiler
JPoint 2016 - Bytecode

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
sap open course for s4hana steps from ECC to s4
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

JavaDay Kiev 2017 - Integration testing with TestContainers