Skip to content

Goals: 1) Create a simple Spring Boot application to manage users; 2) Explore the utilities and annotations that Spring Boot provides for testing; 3) Test using Testcontainers.

Notifications You must be signed in to change notification settings

ivangfr/springboot-testing-mysql

Repository files navigation

springboot-testing-mysql

The goals of this project are to:

  • Create a simple Spring Boot application to manage users called user-service. The database used is MySQL;
  • Explore the utilities and annotations that Spring Boot provides for testing applications;
  • Test using Testcontainers.

Proof-of-Concepts & Articles

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.

Project Diagram

project-diagram

Application

  • user-service

    Spring Boot Web Java application to manage users. The data is stored in MySQL.

    user-service-swagger

Prerequisites

Start Environment

  • Open a terminal and inside the springboot-testing-mysql root folder run:

    docker compose up -d
  • Wait for the MySQL Docker container to be up and running. To check it, run:

    docker ps -a

Start Application

  • In a terminal, make sure you are in the springboot-testing-mysql root folder;

  • Run application:

    ./gradlew user-service:clean user-service:bootRun
  • The Swagger website can be accessed at http://localhost:8080/swagger-ui.html

Shutdown

  • Go to the terminal where user-service is running and press Ctrl+C;

  • In a terminal, inside the springboot-testing-mysql root folder, run the command below to stop and remove the Docker Compose mysql container and network:

    docker compose down -v

Running Unit and Integration Tests

  • In a terminal, navigate to the 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 automatically starts the MySQL 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
    

Useful Commands

  • MySQL
    docker exec -it -e MYSQL_PWD=secret mysql mysql -uroot --database userdb
    SELECT * FROM users;

About

Goals: 1) Create a simple Spring Boot application to manage users; 2) Explore the utilities and annotations that Spring Boot provides for testing; 3) Test using Testcontainers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages