SlideShare a Scribd company logo
Prod-Like Integration Testing for
Distributed Containerized Applications
Maria Gabriella Brodi ⸱ @BrodiMg
Staff Solutions Engineer, VMware
⸺
Cora Iberkleid ⸱ @ciberkleid
Developer Advocate, VMware
Abstract
Integration testing for distributed containerized applications poses new challenges in terms of
practices, tools, and environments for developers who want to carry out more prod-like
integration testing earlier in the development lifecycle.
In-memory databases are useful but cannot provide the level of assurance needed as you test
against a real database. This option is also limited to data services, but not all services provide
an in-memory alternative.
Testcontainers is a framework for instantiating standalone containers for any number of
services to test against. The framework offers some out-of-the-box options, but you can also
provide your own image, and even your own Dockerfile to instantiate the service of your choice.
In this talk, we'll explore testcontainers and push the boundaries in order to explore how they
may be used in conjunction with Cloud Native Buildpacks. This approach has the added benefit
of ensuring that all testing is carried out on the same container stack.
Agenda
- Intro
- Testcontainers 101
- DB integration testing
- Network affinity testing
- Environment parity
- Takeaways
INTRO
What do we mean by “prod-like” integration testing?
● Integration vs Unit tests
● Greater fidelity to run-time conditions
● Type of system
● Network reliability
● OS environment
● Shifted left
● Local developer machine
● Iterate locally
Common Approaches to Integration Test
In Integration tests we are interested in verifying the behavior and interactions of
multiple modules.
For this purpose we can use:
- Shared instances
- Local installation
- In memory solutions
In-memory testing
App
Mock server or
in-memory service
Options:
● Mock server (Wiremock, Loki…)
● In-memory service (h2, hsql...)
Limitations of in-memory testing
App
Mock server or
in-memory service
Limitations:
● Requires framework support
● Behavior differences to real system
● Latency/bandwidth testing can be challenging
● Not every service has an in-memory option
● Differences in security configuration
New challenges with in-memory testing
App
Challenge exacerbated with explosion in microservices
and variety of service options over the last 10 years.
Mock server or
in-memory service
Limitations:
● Requires framework support
● Behavior differences to real system
● Latency/bandwidth testing can be challenging
● Not every service has an in-memory option
● Differences in security configuration
New challenges with in-memory testing
App
Challenge exacerbated with explosion in microservices
and variety of service options over the last 10 years.
Mock server or
in-memory service
Limitations:
● Requires framework support
● Behavior differences to real system
● Latency/bandwidth testing can be challenging
● Not every service has an in-memory option
● Differences in security configuration
Containerization Helps!
● Containerization per se is a big part of the solution
● Docker Compose - works for any framework
However…
● Cumbersome lifecycle management
● Additional skill set for developers to learn
However!
● There is an easier solution :)
Testcontainers: easy testing with external services
Service on Docker
App
Testcontainers
dependency
TESTCONTAINERS 101
Testcontainers intro/overview
● Java library that creates instances of Docker containers for testing
● Supports JUnit4, JUnit5, and Spock
Support for other languages
(check GitHub for more complete information)
Available Modules
● Provides lightweight,
throwaway instances
of common
databases, Selenium
web browsers, and
more
● Can start anything
else that can run in a
Docker container
Why Testcontainers? Where to use them?
● Prod-like systems:
● Easier instantiation of disposable services that lack an in-memory option
● Test against any application that can run as a container
● Integration testing:
● Data access layer integration
● Application integration
● Browser-based acceptance
inspiration...
package org.testcontainers.junit.jupiter;
import ...
class TestcontainersExtension implements BeforeEachCallback, BeforeAllCallback,
AfterEachCallback, AfterAllCallback, ExecutionCondition, TestInstancePostProcessor {
@Testcontainers (JUnit 5)
JUnit5 Extension - intercepts JUnit lifecycle
events and manages container lifecycles
@Testcontainers
public class MyIntegrationTests {
@Container // In JUnit 4, use @Rule/@ClassRule
static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres");
...
@ExtendWith({TestcontainersExtension.class})
@Container (JUnit 5) / @Rule (JUnit 4)
@Testcontainers
public class MyIntegrationTests {
@Container // In JUnit 4, use @Rule/@ClassRule
PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres");
...
Flags TestcontainersExtension about a container to manage
● New container is started/stopped for every test
● Declare as static to re-use the same container
DEMO TIME
TESTCONTAINERS BASICS
“REAL” DATABASE
INTEGRATION TESTING
Close...but different!
...ish
Elephant by Anton from the Noun Project
DEMO TIME
DB INTEGRATION TESTING
NETWORK RELIABILITY
Which Challenges in a Real Environment?
Network can misbehave:
- Increase Latency
- Decrease Bandwidth
- Unexpected Closed Connections
- Changes in Packet Size
And Everything goes … BANANAS
Toxiproxy
A framework for simulating network conditions. It's
made specifically to work in testing, CI and
development environments.
https://github.com/Shopify/toxiproxy
Toxiproxy & Testcontainers
Toxiproxy available as a Testcontainers Module
Started as separate container on the Docker daemon
The toxiproxy container proxies all the traffics to the service container
Requires toxiproxy and service containers to be on the same network
Network Definition
Service on Docker
(e.g. postgres)
Toxiproxy
Network
We can facilitate connections between
containers without exposing ports on the
hosts by using a Network object
App testcontainers
Network Definition
Service on Docker
(e.g. postgres)
Toxiproxy
Network
App testcontainers
A maximum of one network can be shared
between containers.
Service on Docker
(e.g. redis)
DEMO
NETWORK RELIABILITY
ENVIRONMENT
AFFINITY
OS Base Layer
Path to Production - Environment Parity
CI Test Job CI Build Job
Build Layer 1
Build Layer N
OS = ?
Runtime= ?
OS = ?
Runtime= ?
OS = ?
Runtime= ?
Common Approaches
● Test and Build and Run environments often configured separately
○ Test job environment in CI toolchain
○ Build job environment in CI toolchain (separately, sometimes)
○ Run environment often configure in Dockerfile (‘FROM’ base image)
○ Very hard to keep synchronized
● Two-stage Dockerfiles help with specifying same build and run base images
○ Two ‘FROM’ statements in the same Dockerfile
○ Stil, hard to manage across applications at scale
A Better Way: Cloud Native Buildpacks
● Buildpacks provide a consistent way to build images at scale
● Build and run stacks guaranteed to be the same
● Distributed as a standalone “builder” image - easily shared across an
organization
● Polyglot
● Choice in user experience
○ CLI, Maven/Gradle plugin, Kubernetes operator, and more…
● Default configuration of Maven Buildpack:
BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=true package'
Cloud Native Buildpacks (CNB)
CNB Run Image
CI Test Job CNB Builder
CNB BP Layer(s)
CNB App Layer(s)
OS = ✅
Runtime= ✅
OS = ?
Runtime= ?
OS = ✅
Runtime= ✅
● Custom configuration:
BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=false package'
Cloud Native Buildpacks (CNB)
CNB Run Image
Test & Build!
CNB Builder CNB BP Layer(s)
CNB App Layer(s)
OS = ✅
Runtime= ✅
OS = ✅
Runtime= ✅
Test & Build!
CNB Builder
pack build my-springone-app 
--builder paketobuildpacks/builder:base 
--env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package'
Test & Build!
CNB Builder
mvn package
CNB Builder
testcontainers-java
CNB Builder
Hold your horses…
buildpacks can’t start
containers on Docker
Postgres
DOCKER_HOST = unix:///var/run/docker.sock
testcontainers-java
CNB Builder
Postgres
TCP
DOCKER_HOST = unix:///var/run/docker.sock
testcontainers-java
CNB Builder
Postgres
TCP
DOCKER_HOST = unix:///var/run/docker.sock
DOCKER_HOST = tcp://${DOCKER_HOST_IP}:${DOCKER_PORT}
Still respects security
guardrails of CNB ✅
Pack + Testcontainers Docker Host Detection
● We use a common utility (socat) to map the TCP port to the Unix socket
socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
pack build my-springone-app 
--builder paketobuildpacks/builder:base 
--env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package' 
--env DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375
pkill socat
DEMO TIME
ENVIRONMENT AFFINITY
TAKEAWAYS
Get more “prod-like” integration testing using...
★ Testcontainers for improved system affinity
★ Toxiproxy for network resiliency testing
★ CNB with pack CLI and Paketo Buildpacks
Get more “prod-like” integration testing using...
★ Testcontainers for improved system affinity
★ Toxiproxy for network resiliency testing
★ CNB with pack CLI and Paketo Buildpacks
★ And… all from the comfort of your local machine!
Links
Demos:
https://github.com/springone-2021-testcontainers/testcontainers-demo
Testcontainers:
https://www.testcontainers.org
Toxiproxy:
https://github.com/Shopify/toxiproxy
Cloud Native Buildpacks:
https://buildpacks.io
Thank you!
Please join us on Slack
for 15 min of Q&A

More Related Content

What's hot (20)

PDF
Unified Stream and Batch Processing with Apache Flink
DataWorks Summit/Hadoop Summit
 
PDF
JPA and Hibernate
elliando dias
 
PDF
Introduction to Apache Flink - Fast and reliable big data processing
Till Rohrmann
 
PDF
Java spring framework
Rajiv Gupta
 
PPTX
Static typing vs dynamic typing languages
Jawad Khan
 
PDF
A Deep Dive into Spring Application Events
VMware Tanzu
 
PPT
Maven Overview
FastConnect
 
PPTX
Spring JDBCTemplate
Guo Albert
 
PDF
DevNation Live: Kafka and Debezium
Red Hat Developers
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
PDF
Testing Spring Boot Applications
VMware Tanzu
 
PPTX
EJB3 Basics
Emprovise
 
PPTX
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
huguk
 
PPTX
Visitor design patterns
Nishant Mevawala
 
PPTX
Clean architecture
.NET Crowd
 
PDF
실전 서버 부하테스트 노하우
YoungSu Son
 
PPTX
UFT Automation Framework Introduction
Himal Bandara
 
PDF
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
PPTX
Spring Security 5
Jesus Perez Franco
 
Unified Stream and Batch Processing with Apache Flink
DataWorks Summit/Hadoop Summit
 
JPA and Hibernate
elliando dias
 
Introduction to Apache Flink - Fast and reliable big data processing
Till Rohrmann
 
Java spring framework
Rajiv Gupta
 
Static typing vs dynamic typing languages
Jawad Khan
 
A Deep Dive into Spring Application Events
VMware Tanzu
 
Maven Overview
FastConnect
 
Spring JDBCTemplate
Guo Albert
 
DevNation Live: Kafka and Debezium
Red Hat Developers
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
Testing Spring Boot Applications
VMware Tanzu
 
EJB3 Basics
Emprovise
 
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
huguk
 
Visitor design patterns
Nishant Mevawala
 
Clean architecture
.NET Crowd
 
실전 서버 부하테스트 노하우
YoungSu Son
 
UFT Automation Framework Introduction
Himal Bandara
 
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
Spring Security 5
Jesus Perez Franco
 

Similar to Prod-Like Integration Testing for Distributed Containerized Applications (20)

PDF
Level Up Your Integration Testing With Testcontainers
VMware Tanzu
 
PPTX
Simplifying Integration Testing in a Containerized World
ssuser9d4fc7
 
PDF
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
PDF
Testcontainers - Geekout EE 2017 presentation
Richard North
 
PDF
Integration tests: use the containers, Luke!
Roberto Franchini
 
PPTX
Testcontainers: Reliable, Isolated, and Reproducible Testing for External Dep...
ssuser9d4fc7
 
PPTX
Introduction to TestContainers for Integration Testing
QuangDo68
 
PDF
Containerised Testing at Demonware : PyCon Ireland 2016
Thomas Shaw
 
PDF
Scala, docker and testing, oh my! mario camou
J On The Beach
 
PPTX
JLove - Replicating production on your laptop using the magic of containers
Grace Jansen
 
PDF
GeeCON 2017 - TestContainers. Integration testing without the hassle
Anton Arhipov
 
PPTX
JBCN_Testing_With_Containers
Grace Jansen
 
PDF
Automated integration testing of distributed systems with Docker Compose and ...
Boris Kravtsov
 
PPTX
Reality-Driven Testing using TestContainers
Oleksii Holub
 
PDF
Continuous Integration Testing: Fully test your microservices application, ea...
David Stanke
 
PDF
JavaOne 2017 - TestContainers: integration testing without the hassle
Anton Arhipov
 
PDF
Testing containers with TestContainers @ AJUG 7/18/2017
Viktor Gamov
 
PPTX
Continuous integration testing 2019 08
David Stanke
 
PDF
In cluster open source testing framework - Microservices Meetup
Neil Gehani
 
PPTX
Testing microservices with docker
Denis Brusnin
 
Level Up Your Integration Testing With Testcontainers
VMware Tanzu
 
Simplifying Integration Testing in a Containerized World
ssuser9d4fc7
 
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
Testcontainers - Geekout EE 2017 presentation
Richard North
 
Integration tests: use the containers, Luke!
Roberto Franchini
 
Testcontainers: Reliable, Isolated, and Reproducible Testing for External Dep...
ssuser9d4fc7
 
Introduction to TestContainers for Integration Testing
QuangDo68
 
Containerised Testing at Demonware : PyCon Ireland 2016
Thomas Shaw
 
Scala, docker and testing, oh my! mario camou
J On The Beach
 
JLove - Replicating production on your laptop using the magic of containers
Grace Jansen
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
Anton Arhipov
 
JBCN_Testing_With_Containers
Grace Jansen
 
Automated integration testing of distributed systems with Docker Compose and ...
Boris Kravtsov
 
Reality-Driven Testing using TestContainers
Oleksii Holub
 
Continuous Integration Testing: Fully test your microservices application, ea...
David Stanke
 
JavaOne 2017 - TestContainers: integration testing without the hassle
Anton Arhipov
 
Testing containers with TestContainers @ AJUG 7/18/2017
Viktor Gamov
 
Continuous integration testing 2019 08
David Stanke
 
In cluster open source testing framework - Microservices Meetup
Neil Gehani
 
Testing microservices with docker
Denis Brusnin
 
Ad

More from VMware Tanzu (20)

PDF
Spring into AI presented by Dan Vega 5/14
VMware Tanzu
 
PDF
What AI Means For Your Product Strategy And What To Do About It
VMware Tanzu
 
PDF
Make the Right Thing the Obvious Thing at Cardinal Health 2023
VMware Tanzu
 
PPTX
Enhancing DevEx and Simplifying Operations at Scale
VMware Tanzu
 
PDF
Spring Update | July 2023
VMware Tanzu
 
PPTX
Platforms, Platform Engineering, & Platform as a Product
VMware Tanzu
 
PPTX
Building Cloud Ready Apps
VMware Tanzu
 
PDF
Spring Boot 3 And Beyond
VMware Tanzu
 
PDF
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
VMware Tanzu
 
PDF
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
VMware Tanzu
 
PDF
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
VMware Tanzu
 
PPTX
tanzu_developer_connect.pptx
VMware Tanzu
 
PDF
Tanzu Virtual Developer Connect Workshop - French
VMware Tanzu
 
PDF
Tanzu Developer Connect Workshop - English
VMware Tanzu
 
PDF
Virtual Developer Connect Workshop - English
VMware Tanzu
 
PDF
Tanzu Developer Connect - French
VMware Tanzu
 
PDF
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
VMware Tanzu
 
PDF
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
VMware Tanzu
 
PDF
SpringOne Tour: The Influential Software Engineer
VMware Tanzu
 
PDF
SpringOne Tour: Domain-Driven Design: Theory vs Practice
VMware Tanzu
 
Spring into AI presented by Dan Vega 5/14
VMware Tanzu
 
What AI Means For Your Product Strategy And What To Do About It
VMware Tanzu
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
VMware Tanzu
 
Enhancing DevEx and Simplifying Operations at Scale
VMware Tanzu
 
Spring Update | July 2023
VMware Tanzu
 
Platforms, Platform Engineering, & Platform as a Product
VMware Tanzu
 
Building Cloud Ready Apps
VMware Tanzu
 
Spring Boot 3 And Beyond
VMware Tanzu
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
VMware Tanzu
 
tanzu_developer_connect.pptx
VMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
VMware Tanzu
 
Tanzu Developer Connect Workshop - English
VMware Tanzu
 
Virtual Developer Connect Workshop - English
VMware Tanzu
 
Tanzu Developer Connect - French
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
VMware Tanzu
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
VMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
VMware Tanzu
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
VMware Tanzu
 
Ad

Recently uploaded (20)

PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Human Resources Information System (HRIS)
Amity University, Patna
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 

Prod-Like Integration Testing for Distributed Containerized Applications

  • 1. Prod-Like Integration Testing for Distributed Containerized Applications Maria Gabriella Brodi ⸱ @BrodiMg Staff Solutions Engineer, VMware ⸺ Cora Iberkleid ⸱ @ciberkleid Developer Advocate, VMware
  • 2. Abstract Integration testing for distributed containerized applications poses new challenges in terms of practices, tools, and environments for developers who want to carry out more prod-like integration testing earlier in the development lifecycle. In-memory databases are useful but cannot provide the level of assurance needed as you test against a real database. This option is also limited to data services, but not all services provide an in-memory alternative. Testcontainers is a framework for instantiating standalone containers for any number of services to test against. The framework offers some out-of-the-box options, but you can also provide your own image, and even your own Dockerfile to instantiate the service of your choice. In this talk, we'll explore testcontainers and push the boundaries in order to explore how they may be used in conjunction with Cloud Native Buildpacks. This approach has the added benefit of ensuring that all testing is carried out on the same container stack.
  • 3. Agenda - Intro - Testcontainers 101 - DB integration testing - Network affinity testing - Environment parity - Takeaways
  • 5. What do we mean by “prod-like” integration testing? ● Integration vs Unit tests ● Greater fidelity to run-time conditions ● Type of system ● Network reliability ● OS environment ● Shifted left ● Local developer machine ● Iterate locally
  • 6. Common Approaches to Integration Test In Integration tests we are interested in verifying the behavior and interactions of multiple modules. For this purpose we can use: - Shared instances - Local installation - In memory solutions
  • 7. In-memory testing App Mock server or in-memory service Options: ● Mock server (Wiremock, Loki…) ● In-memory service (h2, hsql...)
  • 8. Limitations of in-memory testing App Mock server or in-memory service Limitations: ● Requires framework support ● Behavior differences to real system ● Latency/bandwidth testing can be challenging ● Not every service has an in-memory option ● Differences in security configuration
  • 9. New challenges with in-memory testing App Challenge exacerbated with explosion in microservices and variety of service options over the last 10 years. Mock server or in-memory service Limitations: ● Requires framework support ● Behavior differences to real system ● Latency/bandwidth testing can be challenging ● Not every service has an in-memory option ● Differences in security configuration
  • 10. New challenges with in-memory testing App Challenge exacerbated with explosion in microservices and variety of service options over the last 10 years. Mock server or in-memory service Limitations: ● Requires framework support ● Behavior differences to real system ● Latency/bandwidth testing can be challenging ● Not every service has an in-memory option ● Differences in security configuration
  • 11. Containerization Helps! ● Containerization per se is a big part of the solution ● Docker Compose - works for any framework However… ● Cumbersome lifecycle management ● Additional skill set for developers to learn However! ● There is an easier solution :)
  • 12. Testcontainers: easy testing with external services Service on Docker App Testcontainers dependency
  • 14. Testcontainers intro/overview ● Java library that creates instances of Docker containers for testing ● Supports JUnit4, JUnit5, and Spock
  • 15. Support for other languages (check GitHub for more complete information)
  • 16. Available Modules ● Provides lightweight, throwaway instances of common databases, Selenium web browsers, and more ● Can start anything else that can run in a Docker container
  • 17. Why Testcontainers? Where to use them? ● Prod-like systems: ● Easier instantiation of disposable services that lack an in-memory option ● Test against any application that can run as a container ● Integration testing: ● Data access layer integration ● Application integration ● Browser-based acceptance
  • 19. package org.testcontainers.junit.jupiter; import ... class TestcontainersExtension implements BeforeEachCallback, BeforeAllCallback, AfterEachCallback, AfterAllCallback, ExecutionCondition, TestInstancePostProcessor { @Testcontainers (JUnit 5) JUnit5 Extension - intercepts JUnit lifecycle events and manages container lifecycles @Testcontainers public class MyIntegrationTests { @Container // In JUnit 4, use @Rule/@ClassRule static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres"); ... @ExtendWith({TestcontainersExtension.class})
  • 20. @Container (JUnit 5) / @Rule (JUnit 4) @Testcontainers public class MyIntegrationTests { @Container // In JUnit 4, use @Rule/@ClassRule PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres"); ... Flags TestcontainersExtension about a container to manage ● New container is started/stopped for every test ● Declare as static to re-use the same container
  • 23. Close...but different! ...ish Elephant by Anton from the Noun Project
  • 26. Which Challenges in a Real Environment? Network can misbehave: - Increase Latency - Decrease Bandwidth - Unexpected Closed Connections - Changes in Packet Size And Everything goes … BANANAS
  • 27. Toxiproxy A framework for simulating network conditions. It's made specifically to work in testing, CI and development environments. https://github.com/Shopify/toxiproxy
  • 28. Toxiproxy & Testcontainers Toxiproxy available as a Testcontainers Module Started as separate container on the Docker daemon The toxiproxy container proxies all the traffics to the service container Requires toxiproxy and service containers to be on the same network
  • 29. Network Definition Service on Docker (e.g. postgres) Toxiproxy Network We can facilitate connections between containers without exposing ports on the hosts by using a Network object App testcontainers
  • 30. Network Definition Service on Docker (e.g. postgres) Toxiproxy Network App testcontainers A maximum of one network can be shared between containers. Service on Docker (e.g. redis)
  • 33. OS Base Layer Path to Production - Environment Parity CI Test Job CI Build Job Build Layer 1 Build Layer N OS = ? Runtime= ? OS = ? Runtime= ? OS = ? Runtime= ?
  • 34. Common Approaches ● Test and Build and Run environments often configured separately ○ Test job environment in CI toolchain ○ Build job environment in CI toolchain (separately, sometimes) ○ Run environment often configure in Dockerfile (‘FROM’ base image) ○ Very hard to keep synchronized ● Two-stage Dockerfiles help with specifying same build and run base images ○ Two ‘FROM’ statements in the same Dockerfile ○ Stil, hard to manage across applications at scale
  • 35. A Better Way: Cloud Native Buildpacks ● Buildpacks provide a consistent way to build images at scale ● Build and run stacks guaranteed to be the same ● Distributed as a standalone “builder” image - easily shared across an organization ● Polyglot ● Choice in user experience ○ CLI, Maven/Gradle plugin, Kubernetes operator, and more…
  • 36. ● Default configuration of Maven Buildpack: BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=true package' Cloud Native Buildpacks (CNB) CNB Run Image CI Test Job CNB Builder CNB BP Layer(s) CNB App Layer(s) OS = ✅ Runtime= ✅ OS = ? Runtime= ? OS = ✅ Runtime= ✅
  • 37. ● Custom configuration: BP_MAVEN_BUILD_ARGUMENTS='-Dmaven.test.skip=false package' Cloud Native Buildpacks (CNB) CNB Run Image Test & Build! CNB Builder CNB BP Layer(s) CNB App Layer(s) OS = ✅ Runtime= ✅ OS = ✅ Runtime= ✅
  • 38. Test & Build! CNB Builder pack build my-springone-app --builder paketobuildpacks/builder:base --env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package'
  • 39. Test & Build! CNB Builder
  • 41. testcontainers-java CNB Builder Hold your horses… buildpacks can’t start containers on Docker Postgres DOCKER_HOST = unix:///var/run/docker.sock
  • 43. testcontainers-java CNB Builder Postgres TCP DOCKER_HOST = unix:///var/run/docker.sock DOCKER_HOST = tcp://${DOCKER_HOST_IP}:${DOCKER_PORT} Still respects security guardrails of CNB ✅
  • 44. Pack + Testcontainers Docker Host Detection ● We use a common utility (socat) to map the TCP port to the Unix socket socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock & pack build my-springone-app --builder paketobuildpacks/builder:base --env BP_MAVEN_BUILD_ARGUMENTS='Dtest=Demo2_Toxiproxy_Tst test package' --env DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375 pkill socat
  • 47. Get more “prod-like” integration testing using... ★ Testcontainers for improved system affinity ★ Toxiproxy for network resiliency testing ★ CNB with pack CLI and Paketo Buildpacks
  • 48. Get more “prod-like” integration testing using... ★ Testcontainers for improved system affinity ★ Toxiproxy for network resiliency testing ★ CNB with pack CLI and Paketo Buildpacks ★ And… all from the comfort of your local machine!
  • 50. Thank you! Please join us on Slack for 15 min of Q&A