To test our Spring Boot application we need to test the URLs we are handling in our Controller
, which means we need to write a test class for each Controller
.
We need to add the following dependencies to our build.gradle
file for testing:
// Testing testCompile group: 'junit', name: 'junit', version: '4.12' testCompile "org.springframework.boot:spring-boot-starter-test"
All the tests are put in the test
module with the same package name of the code. Mainly the test cases are written for the Controller
, but you can even write for Repository
for which you'll need to mock the database using Mockito
or some other mocking library.
The MockMvc
class is the entry point for performing server-side tests. We can perform HTTP requests such as GET
, POST
, and others on the URLs to test the REST endpoints.
MessageControllerTests
: Test cases for the MessageController
are written in human readable names using `
while writing function names.
Consider the following...