Skip to content

Opinionated best practices for Spring integration tests

License

Notifications You must be signed in to change notification settings

fbeaufume/spring-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Integration tests with Spring

This repository is a sample application for my Getting started with Spring tests and Switching between H2 and Testcontainers in Spring tests articles.

This simple Spring Boot web application shows several opinionated best practices for Spring tests:

  • ItemControllerServerTest: an example of "server" web integration test for a REST controller using MockMvc
  • ItemControllerClientTest: an example of "client" web integration test for a REST controller using REST Assured
  • BaseTest: a base integration test class for the above test classes
  • ItemControllerSliceTest: an example of a "web slice" integration test for a REST controller (uses a dedicated Spring application context)
  • SumTest: a sample parameterized unit test class

For extra information about Spring application context caching in tests, see Context Caching.

To run the tests using H2 execute mvn test.

To run the tests using PostgreSQL execute mvn test -Dtest.profiles=test,postgres. Note that this uses Testcontainers, and so requires Docker.

This application also uses JUnit Insights to generate some test execution metrics, see HTML files in target/junit-insights-reports.

About

Opinionated best practices for Spring integration tests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages