You develop a weather app, proposing simple use cases:
- to consult the weather of your pre-saved cities,
- to add a city with GPS coordinations.
(Estimate time : 10 minutes)
Make sure you have the following prerequisites installed on your machine:
- nodejs > 10
- Java 11
- Docker
- Maven
- Your favorite Java IDE
- Docker images for backend, frontend & weather api are built
When you have all prerequisites installed, let's build docker images required to be able to write & execute tests with testcontainers:
docker pull mysql:8
docker build -t 7timer:0.0.1-SNAPSHOT e2e/src/test/resources/7timer/
docker build -t zenika-weather-front:0.0.1-SNAPSHOT front/
docker build -t zenika-weather-back:0.0.1-SNAPSHOT back/
Setting up the requirements should be done now. You can check everything's going well with the usage section above.
(Estimate time : 5 minutes)
Go to front/
directory.
As it's not necessary for our workshop to launch the interface, you can skip this step, which downloads nodes dependencies defined in package.json and then starts the interface. Otherwise, you can type below commands. When the start's done, visit http://localhost:4200 in your browser.
npm install
npm start
Go to back/
directory.
We deploy the back part in a Docker container too. So, you don't have to run it manually but if you want to, let's play maven commands to download maven dependencies define in pom.xml, build image and run the back:
mvn install
mvn spring-boot:run
We have a SQL database in a docker container.
The schema table will be created with the schema.sql
file from back/
directory when we start the back.
To deploy and rightly configure the container, let's run as below:
docker run --name weather-db -i --rm -e MYSQL_DATABASE=zenika-weather -e MYSQL_USER=zenika -e MYSQL_PASSWORD=zenika-password -e MYSQL_RANDOM_ROOT_PASSWORD=true -p 3306:3306 mysql:8.0.28
Don't forget to stop mysql container for the workshop:
docker stop weather-db
(Estimate time : 30 minutes)
For now, integration test depends on MySQL instance started locally. We would evolve the test to start a MySQL docker image.
Step 1: Migrate integration test CitiesControllerTest
with Generic container.
Step 2: Migrate integration test CitiesControllerTest
with MySQL container.
Step 3: Migrate integration test CitiesControllerTest
with testcontainers driver.
(Estimate time : 35 minutes)
As a last step, our functional test depends on services (front, api, db, weather api) started locally. We would evolve the test to start the platform inside a containers network.
Step 3: Migrate functional test to use containers network.
Step 4: Migrate functional test to use docker compose.
Step 5 (Bonus): Migrate functional test to use web driver container.
Workshop's done: Congratulations! 🏆️🎉
🎓 Solutions
Need help?
Take a look at our solution for each step.
Every improvement is welcome!
- Typescript
- Kotlin
- Angular
- Spring
- Testcontainers

