Workshop Testcontainers

A presentation at Workshop Testcontainers with Spring Boot in April 2023 in Utrecht, Netherlands by Bas Stoker

Slide 1

Slide 1

Workshop Testcontainers

Slide 2

Slide 2

Schedule • Current state of testing • Testcontainers •🧪 Lab 1 •🧪 Lab 2 •🧪 Lab 3 introduction

Slide 3

Slide 3

Your test is called what?!

Slide 4

Slide 4

https://martinfowler.com/bliki/TestPyramid.html

Slide 5

Slide 5

https://martinfowler.com/bliki/TestPyramid.html

Slide 6

Slide 6

Slide 7

Slide 7

“Write tests. Not too many. Mostly integration.” https://kentcdodds.com/blog/write-tests

Slide 8

Slide 8

“You’re probably mocking too much.” https://medium.com/extreme-programming/testsdependencies-65f592a46529

Slide 9

Slide 9

Slide 10

Slide 10

Slide 11

Slide 11

Testcontainers

Slide 12

Slide 12

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

Slide 16

Slide 16

Slide 17

Slide 17

Testcontainers Docker

Slide 18

Slide 18

“Docker is a great abstraction”

Slide 19

Slide 19

🧪 Our Demo App • Java • Uses • Uses 17 & Spring boot a database (PostgreSQL) Keycloak for authentication • There is frontend available • Available as a Docker Image purposes for demo

Slide 20

Slide 20

Slide 21

Slide 21

🧪 Lab 1. • Goal: run the app • App consists of 4 • Database • Keycloak • Backend • User Interface manually (using Docker) parts:

Slide 22

Slide 22

🧪Lab 1.

Slide 23

Slide 23

🧪Lab 1.

Slide 24

Slide 24

🧪Lab 1.

Slide 25

Slide 25

🧪Lab 1.

Slide 26

Slide 26

🧪Lab 1.

Slide 27

Slide 27

Slide 28

Slide 28

Slide 29

Slide 29

Food :-)

Slide 30

Slide 30

🧪 Lab 2. • Goal: Test database access layer • Using JUnit test lifecycle • Using PostgreSQL Testcontainer • Using Spring Injection of properties dynamically

Slide 31

Slide 31

🧪 Lab 2.

Slide 32

Slide 32

🧪Lab Hint: 2. datasource-url wordt ook wel JDBC-url genoemd soms 😄

Slide 33

Slide 33

🧪Lab 2. • Solution • Extra nice things: - convenience annotations • Questions

Slide 34

Slide 34

🧪 Lab 3. • Goal: • With • Happy Test entire app using Testcontainers enabled authentication Duck, eh, Bug hunt!

Slide 35

Slide 35

🧪Lab 3.

Slide 36

Slide 36

Slide 37

Slide 37

Bedankt voor jullie aanwezigheid!