From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Writing integration tests for cache

Writing integration tests for cache

From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Start my 1-month free trial

Writing integration tests for cache

- [Instructor] Ever wonder how to test a hard problem, like caching? We use the cache, to protect the database or to avoid cost-intensive calculations. And spring provides an abstraction layer, for implementing a cache. But how do we ensure, that our cache is really working as expected? What we need is to ensure in cases, when we are retrieving the same student from our service, we want to verify we are not hitting the database, every single time. We will start, by creating a new test class. And we will call it Student Cache Test. Let's create new test method, and name it, Gets Students By ID, for multiple requests, is retrieved from cache. In the given part, we will create some random student ID. We need to inject student service in our test, and in the Web part, simulate, multiple requests to the service layer, by calling Gets Students By ID, multiple times for the same student ID. Since we need to test interaction with a repository, this means, we need the kind of way to check how…

Contents