The goals of this project are:
- Create a simple
Spring Boot
application to manage users calleduser-service
. The database used isMySQL
; - Explore the utilities and annotations that
Spring Boot
provides for testing applications; - Test using
Testcontainers
.
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
-
Open a terminal and inside
springboot-testing-mysql
root folder run:docker compose up -d
-
Wait for
MySQL
Docker container to be up and running. To check it, run:docker compose ps
-
In a terminal, make sure you are in
springboot-testing-mysql
root folder; -
Run application:
./gradlew user-service:clean user-service:bootRun
-
Swagger website is http://localhost:8080/swagger-ui.html
-
Go to the terminal where
user-service
is running and pressCtrl+C
; -
In a terminal and inside
springboot-testing-mysql
root folder, run to command below to stop and remove docker composemysql
container and network:docker compose down -v
-
In a terminal, navigate to
springboot-testing-mysql
root folder; -
Running Tests
-
Unit Tests only:
./gradlew user-service:clean user-service:cleanTest user-service:test
-
Unit and Integration Tests:
./gradlew user-service:clean user-service:cleanTest user-service:check user-service:integrationTest
Note: During the tests,
Testcontainers
starts automaticallyMySQL
Docker container before the tests begin and shuts it down when the tests finish.
-
-
Unit Test Report can be found at:
user-service/build/reports/tests/test/index.html
-
Integration Test Report can be found at:
user-service/build/reports/tests/integrationTest/index.html
- MySQL
docker exec -it -e MYSQL_PWD=secret mysql mysql -uroot --database userdb SELECT * FROM users;