If testing Spring Data JPA transactions is easier with Spring Boot, then the following recipe that involves testing RESTful services is also quite straightforward and convenient as compared to the usual MockMvc
style.
Again, open the DEPARTMENT
microservices project, which is ch10-deptservice
, and add the following test classes that will validate the results of each RESTful service.
Let us implement test cases for each RESTful service of a microservice by performing the following steps:
- Just like in the previous recipe, add the needed Spring Test starter POM dependency in the project's
pom.xml
file.
- Inside
src/test/java
, create anorg.packt.microservice.core.test
package and drop a test class that executes blocking RESTful services usingorg.springframework.boot.test.web.client.TestRestTemplate
:
import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest...