From the course: Test-Driven Development in Spring Boot with JUnit and Mockito

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Integration testing with an in-memory database

Integration testing with an in-memory database

- [Instructor] By default, DataJpaTest sets up an in-memory h2 database for testing. So we might not need any additional configuration. In our pom.xml we have the h2 dependency. In this case, we're using it both for testing and for a real application. The main reason I chose that is so that we don't have to set up a custom database on your computer and run into issues with that. However, you'd not use the h2 database if you actually want to implement a task API because the data is gone every time you start the application. Because it's in so-called in memory application, it lives in the memory of the app, which is gone when the app shuts down. So actually our repository tests are already integration tests because they interact with the h2 database. Let's demonstrate this by the testing the deletion of a task. So in our task repository test, I will write void test delete task, and of course this is going to be a test method. And in here I'll have three parts. Again, I have my arrange…

Contents