Posts

Showing posts with the label MockMVC

Spring Data JPA and H2

Image
Spring Data Spring Data makes persistence much easier. I personally not a huge fan of JPA and ORMs.  However, I know lots of engineers like it and I respect different preferences. Have different preferences in different services is totally fine. However, doing that in shared libs is NO-NO. Today I want to cover a bit more about how we can use Spring Data JPA and H2 database for testing. Speed matters. Combining H2 and MockMVC we can speed up tests considerably. I made a simple POC showing how we can configure and use Spring Data JPA with H2 and do proper testing using MockMVC capabilities. I also show how to use the H2 Console so we can query the database. Spring-Data makes persistence much more concise and leverages lots of common functionality for us. So Let's get started. 

Tests with Spring Boot MockMVC

Image
Spring and Spring Boot provide several ways to test our applications/services. Recently I made a post and video about Testing approaches that might be interesting for you. Previously I also made a post and video about TestRestTemplate  and mocks . For this post, I want to focus a bit on the MockMVC capability. MockMVC has a FakeDispatcher servlet(It will feel pretty real) simulating the MVC stack, however, there are no real network connections being made in practice. So MockMVC provides a lightweight way to test controllers as fast as possible. For this post, we will see a simple POC I wrote with a video going to set up a Spring Boot application and also test some scenarios with the MockMVC feature. So Let's Get Started!