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 MockMvcItemControllerClientTest
: an example of "client" web integration test for a REST controller using REST AssuredBaseTest
: a base integration test class for the above test classesItemControllerSliceTest
: 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.