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

Unlock the full course today

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

Solution: Write an integration test for exceptions

Solution: Write an integration test for exceptions

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

Start my 1-month free trial

Solution: Write an integration test for exceptions

(upbeat music) - [Instructor} How was the Challenge? Did you struggle or was it easy? Even though we had to change a few lines of code, testing exceptions is no easy thing to do. I will walk you through the solution. First, on Student Service Desk, we need to create new method. Get student by ID when missing student not found exception thrown. Again, let's use given-when-then structure. Since we want to simulate missing data scenario we don't need to pre-populate our database with students. We also don't need to mock out any behavior since you're dealing with a real repository. We only need some random ID for which we know there is no student. When it comes to asserting exceptions, AssertJ comes with many different styles and it's up to you which one you find most readable. For example, we can use non-BDD style with assert that exception of type or with assert that thrown by where when and then are part of the same line of code. If you prefer a BDD style, we can separate catching and…

Contents