Skip to content

How to write unit and integration tests for Spring Boot. Includes mock mvc and testcontainers.

Notifications You must be signed in to change notification settings

Gtomika/spring-boot-testing-demo

Repository files navigation

Spring Boot testing

This is a demo Spring boot app: it only contains 1 controller with a few endpoints. Data is stored in a PostgreSQL database.

Unit testing

Unit testing example provided for one class, a service. Dependencies (the database) are mocked out.

Test suite is not complete, but the other classes could be tested similarly.

Integration testing

Integration tests launch the entire app. During these tests and actual Postgres DB is launched in Docker, which is then destroyed after the tests end. This functionality is provided by the Testcontainers framework.

MockMvc is used to make HTTP requests to the application.

Test suite is not complete, but the other endpoints could be tested similarly.

CI/CD

Sample GitHub Actions pipeline is provided which runs the unit and integration tests, with Gradle. This pipeline can be triggered manually, or by pushing source code changes to master.

About

How to write unit and integration tests for Spring Boot. Includes mock mvc and testcontainers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages