Integration testing on REST urls with Spring Boot

We are building a Spring Boot application with a REST interface and at some point we wanted to test our REST interface, and if possible, integrate this testing with our regular unit tests. One way of doing this, would be to @Autowire our REST controllers and call our endpoints using that. However, this won’t give full converage, since it will skip things like JSON deserialisation and global exception handling. So the ideal situation for us would be to start our application when the unit test start, and close it again, after the last unit test.
It just so happens that Spring Boot does this all for us with one annotation: @IntegrationTest.
Here is an example implementation of an abstract class you can use for your unit-tests which will automatically start the application prior to starting your unit tests, caching it, and close it again at the end.

2 thoughts on “Integration testing on REST urls with Spring Boot

  1. Instead of using both


    you can use:

    @WebIntegrationTest(randomPort = true)

    In my opinion that more expressive.

  2. Thank you, that works as well indeed. (And is also about the 3rd way i read about to do this by concept now, its is getting hard keeping track)

Leave a Reply

Your email address will not be published. Required fields are marked *