SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Creating Realistic
Unit Tests with
Testcontainers
Paul Balogh, @javaducky
Disclaimer
Paul is not a part of Testcontainers nor Docker.
This is a “first look” presentation.
He is simply interested in improving reliability
with Continuous Delivery.
Forward complaints to
1
2
3
4
What’s with unit tests?
@Test - Real-life applications, i.e. “the demo”
@AfterAll - What did we learn?
Act I
@BeforeAll - Overview of Testcontainers
Difficulties
Unit testing can be difficult and controversial
- What coverage % is appropriate?
- Tests should be idempotent; requires that
dependencies should not be modified
- Mocks can be brittle and unrealistic
- Can provide false sense of security
Sorry…I don’t have the answer
But, there is help!
1
2
3
4
What’s with unit tests?
Act II
@BeforeAll - Overview of Testcontainers
@Test - Real-life applications, i.e. “the demo”
@AfterAll - What did we learn?
an open source framework for providing throwaway,
lightweight instances of databases, [...], or just about
anything that can run in a Docker container
Overview
- Test dependencies as code
No surprises, configured within your source code!
- Support for many languages
Besides Go, can be used with Java, .NET, Python, Rust, Ruby, and more.
- Test anything you can containerize
Over 50 modules available for databases, message brokers, and more.
- “Dev-first” integration testing
Shift testing to the left and find issues earlier.
https://testcontainers.com/
Overview
Supporting Go since 2018!
Overview
Over 50 modules available…
Overview
>>
AtomicJar becomes part of Docker in December, 2023.
Usage
// Create and start the container
container, err := testcontainers.GenericContainer(
ctx,
testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "redis:5.0.3-alpine",
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
},
Started: true,
}
)
// Get your connection string for your client
connStr, err := container.ConnectionString(ctx, “sslmode=disable”)
if err != nil {
t.Fatal(err)
}
// Create your client
rdb := redis.NewClient(&redis.Options{
Addr: connStr,
Password: “”,
DB: 0,
})
1. Specify your target in
code; no surprises
2. Define what it means to
be ready; flexible checks
3. Configure your client
4. Test your integration
2
3
4
@Test - Real-life applications, “the demo”
Act III
1 What’s with unit tests?
@BeforeAll - Overview of Testcontainers
@AfterAll - What did we learn?
WeeSVC
the tiny microservice
What is WeeSVC?
- An example microservice with RESTful APIs
- Backed by a relational database
- Many implementations; same API requirements
- Inspired by TodoMVC (https://todomvc.com/)
- Compatibility (Contract) testing with k6
- Started way back in 2019!
What is WeeSVC?
Highlights of the Go implementation include:
- Gorilla Mux for request routing
- GORM for database abstraction and migrations
Admittedly, this is overkill.
- RDBMS support for SQLite and Postgres
What was added?
- Tests for database layer, db/place.go
- Seed an ephemeral Postgres instance
- Perform CRUD operations in isolation
Multiple examples in example-testcontainer-usage branch!
- Test compliance of API, api/place.go
- Multiple containers: Service and k6
Code Review
https://github.com/weesvc/weesvc-gorilla
THIS SLIDE INTENTIONALLY LEFT BLANK
What’s next?
- Create a profiling suite for simulated load
- Automate creation of comparative analyses
- Add more languages and frameworks
- Contributors welcome and appreciated!
2
3
4
@Test - Real-life applications, i.e. “the demo”
@AfterAll - What did we learn?
Act IV
@BeforeAll - Overview of Testcontainers
1 What’s with unit tests?
What did we learn?
TDD principles influence system design to facilitate
unit tests; this is both good and bad.
- Good: Encourages abstractions using patterns
- Bad: Excess abstraction can make code difficult to
grok
“Clear is better than clever.”
What did we learn?
Testcontainers enable isolation with real dependencies.
- Mocks can drift from reality, with issues creeping up in
later stages of your development lifecycle
- Testing with real dependencies enables earlier detection
of incompatibilities and conflicts
“Don’t panic.” - Different context, I know, but you won’t break things!
What did we learn?
Testcontainers provide consistent experience.
- Executes the same locally as within CICD pipeline
- Test resources are automatically cleaned up
- Wait strategies ensure dependencies are available
Sweet.
Evaluation
Based upon Paul’s very subjective scoring…
Evaluation
- Easy to get started
- Fast; no significant overhead*
- Flexible options for usage
- YES…you should absolutely use this!
A
+
Thank you!
Connect with Paul as
@javaducky or linkedin/in/pabalogh
https://github.com/weesvc/weesvc-gorilla

Contenu connexe

Similaire à Creating Realistic Unit Tests with Testcontainers

Netw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire classNetw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire classJohnnyBryant1
 
Netw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire classNetw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire classCarlosbhakta
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4Billie Berzinskas
 
2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the TrenchesNicolas Fränkel
 
What is OpenStack DefCore, Altanta Conference
What is OpenStack DefCore, Altanta ConferenceWhat is OpenStack DefCore, Altanta Conference
What is OpenStack DefCore, Altanta Conferencerhirschfeld
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellPVS-Studio
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroPaul Boos
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...Yevgeniy Brikman
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignJames Phillips
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxVictor Rentea
 
Common primitives in Docker environments
Common primitives in Docker environmentsCommon primitives in Docker environments
Common primitives in Docker environmentsalexandru giurgiu
 
Security Tips to run Docker in Production
Security Tips to run Docker in ProductionSecurity Tips to run Docker in Production
Security Tips to run Docker in ProductionGianluca Arbezzano
 
[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to TestZsolt Fabok
 

Similaire à Creating Realistic Unit Tests with Testcontainers (20)

Netw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire classNetw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire class
 
Netw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire classNetw450 advanced network security with lab entire class
Netw450 advanced network security with lab entire class
 
L2624 labriola
L2624 labriolaL2624 labriola
L2624 labriola
 
A battle tested CI/CD Pipeline
A battle tested CI/CD PipelineA battle tested CI/CD Pipeline
A battle tested CI/CD Pipeline
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
 
2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches
 
Arquillian
ArquillianArquillian
Arquillian
 
What is OpenStack DefCore, Altanta Conference
What is OpenStack DefCore, Altanta ConferenceWhat is OpenStack DefCore, Altanta Conference
What is OpenStack DefCore, Altanta Conference
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class Design
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
 
Testing 101
Testing 101Testing 101
Testing 101
 
Testing w-mocks
Testing w-mocksTesting w-mocks
Testing w-mocks
 
Common primitives in Docker environments
Common primitives in Docker environmentsCommon primitives in Docker environments
Common primitives in Docker environments
 
Security Tips to run Docker in Production
Security Tips to run Docker in ProductionSecurity Tips to run Docker in Production
Security Tips to run Docker in Production
 
[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test
 

Plus de Paul Balogh

Running distributed load tests with k6
Running distributed load tests with k6Running distributed load tests with k6
Running distributed load tests with k6Paul Balogh
 
Trace-based Testing with Tracetest
Trace-based Testing with TracetestTrace-based Testing with Tracetest
Trace-based Testing with TracetestPaul Balogh
 
Reliability Pipelines With Keptn Quality Gates
Reliability Pipelines With Keptn Quality GatesReliability Pipelines With Keptn Quality Gates
Reliability Pipelines With Keptn Quality GatesPaul Balogh
 
Embracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You GrowEmbracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You GrowPaul Balogh
 
It's just a jump to the left...
It's just a jump to the left...It's just a jump to the left...
It's just a jump to the left...Paul Balogh
 
StLGo Meeting Intro, March 2020
StLGo Meeting Intro, March 2020StLGo Meeting Intro, March 2020
StLGo Meeting Intro, March 2020Paul Balogh
 
2020 02-26-meeting intro
2020 02-26-meeting intro2020 02-26-meeting intro
2020 02-26-meeting introPaul Balogh
 
Let's Go @ St. Louis CocoaHeads
Let's Go @ St. Louis CocoaHeadsLet's Go @ St. Louis CocoaHeads
Let's Go @ St. Louis CocoaHeadsPaul Balogh
 

Plus de Paul Balogh (8)

Running distributed load tests with k6
Running distributed load tests with k6Running distributed load tests with k6
Running distributed load tests with k6
 
Trace-based Testing with Tracetest
Trace-based Testing with TracetestTrace-based Testing with Tracetest
Trace-based Testing with Tracetest
 
Reliability Pipelines With Keptn Quality Gates
Reliability Pipelines With Keptn Quality GatesReliability Pipelines With Keptn Quality Gates
Reliability Pipelines With Keptn Quality Gates
 
Embracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You GrowEmbracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You Grow
 
It's just a jump to the left...
It's just a jump to the left...It's just a jump to the left...
It's just a jump to the left...
 
StLGo Meeting Intro, March 2020
StLGo Meeting Intro, March 2020StLGo Meeting Intro, March 2020
StLGo Meeting Intro, March 2020
 
2020 02-26-meeting intro
2020 02-26-meeting intro2020 02-26-meeting intro
2020 02-26-meeting intro
 
Let's Go @ St. Louis CocoaHeads
Let's Go @ St. Louis CocoaHeadsLet's Go @ St. Louis CocoaHeads
Let's Go @ St. Louis CocoaHeads
 

Dernier

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Dernier (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Creating Realistic Unit Tests with Testcontainers

  • 1. Creating Realistic Unit Tests with Testcontainers Paul Balogh, @javaducky
  • 2. Disclaimer Paul is not a part of Testcontainers nor Docker. This is a “first look” presentation. He is simply interested in improving reliability with Continuous Delivery. Forward complaints to
  • 3. 1 2 3 4 What’s with unit tests? @Test - Real-life applications, i.e. “the demo” @AfterAll - What did we learn? Act I @BeforeAll - Overview of Testcontainers
  • 4. Difficulties Unit testing can be difficult and controversial - What coverage % is appropriate? - Tests should be idempotent; requires that dependencies should not be modified - Mocks can be brittle and unrealistic - Can provide false sense of security
  • 5. Sorry…I don’t have the answer But, there is help!
  • 6. 1 2 3 4 What’s with unit tests? Act II @BeforeAll - Overview of Testcontainers @Test - Real-life applications, i.e. “the demo” @AfterAll - What did we learn?
  • 7. an open source framework for providing throwaway, lightweight instances of databases, [...], or just about anything that can run in a Docker container
  • 8. Overview - Test dependencies as code No surprises, configured within your source code! - Support for many languages Besides Go, can be used with Java, .NET, Python, Rust, Ruby, and more. - Test anything you can containerize Over 50 modules available for databases, message brokers, and more. - “Dev-first” integration testing Shift testing to the left and find issues earlier. https://testcontainers.com/
  • 10. Overview Over 50 modules available…
  • 11. Overview >> AtomicJar becomes part of Docker in December, 2023.
  • 12. Usage // Create and start the container container, err := testcontainers.GenericContainer( ctx, testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ Image: "redis:5.0.3-alpine", ExposedPorts: []string{"6379/tcp"}, WaitingFor: wait.ForLog("Ready to accept connections"), }, Started: true, } ) // Get your connection string for your client connStr, err := container.ConnectionString(ctx, “sslmode=disable”) if err != nil { t.Fatal(err) } // Create your client rdb := redis.NewClient(&redis.Options{ Addr: connStr, Password: “”, DB: 0, }) 1. Specify your target in code; no surprises 2. Define what it means to be ready; flexible checks 3. Configure your client 4. Test your integration
  • 13. 2 3 4 @Test - Real-life applications, “the demo” Act III 1 What’s with unit tests? @BeforeAll - Overview of Testcontainers @AfterAll - What did we learn?
  • 15. What is WeeSVC? - An example microservice with RESTful APIs - Backed by a relational database - Many implementations; same API requirements - Inspired by TodoMVC (https://todomvc.com/) - Compatibility (Contract) testing with k6 - Started way back in 2019!
  • 16. What is WeeSVC? Highlights of the Go implementation include: - Gorilla Mux for request routing - GORM for database abstraction and migrations Admittedly, this is overkill. - RDBMS support for SQLite and Postgres
  • 17. What was added? - Tests for database layer, db/place.go - Seed an ephemeral Postgres instance - Perform CRUD operations in isolation Multiple examples in example-testcontainer-usage branch! - Test compliance of API, api/place.go - Multiple containers: Service and k6
  • 20. What’s next? - Create a profiling suite for simulated load - Automate creation of comparative analyses - Add more languages and frameworks - Contributors welcome and appreciated!
  • 21. 2 3 4 @Test - Real-life applications, i.e. “the demo” @AfterAll - What did we learn? Act IV @BeforeAll - Overview of Testcontainers 1 What’s with unit tests?
  • 22. What did we learn? TDD principles influence system design to facilitate unit tests; this is both good and bad. - Good: Encourages abstractions using patterns - Bad: Excess abstraction can make code difficult to grok “Clear is better than clever.”
  • 23. What did we learn? Testcontainers enable isolation with real dependencies. - Mocks can drift from reality, with issues creeping up in later stages of your development lifecycle - Testing with real dependencies enables earlier detection of incompatibilities and conflicts “Don’t panic.” - Different context, I know, but you won’t break things!
  • 24. What did we learn? Testcontainers provide consistent experience. - Executes the same locally as within CICD pipeline - Test resources are automatically cleaned up - Wait strategies ensure dependencies are available Sweet.
  • 25. Evaluation Based upon Paul’s very subjective scoring…
  • 26. Evaluation - Easy to get started - Fast; no significant overhead* - Flexible options for usage - YES…you should absolutely use this! A +
  • 27. Thank you! Connect with Paul as @javaducky or linkedin/in/pabalogh https://github.com/weesvc/weesvc-gorilla