From the course: Practical Test-Driven Development for Java Programmers

Unlock this course with a free trial

Join today to access over 22,700 courses taught by industry experts.

Why mocks are useful

Why mocks are useful

- Hello, and welcome back. In this chapter we're going to continue with our project, and we now want to write some tests that check the following functionality. If we are trying to get the locator code for a book where we have the information about the book in the local database, then we'll get that data from the local database. If we're looking for a book which is not in the local database, then we'll get the data from the third party web service. Now up until this point, we've been testing data. Every test we've written has resulted in us asserting that the value of some object matches what we expected. What we now need to do is to write tests for something slightly different. We're now going to be testing behavior. Let's suppose we implement the connection to our database system as another implementation of the same interface that we built in the last chapter for our web service. So both our web service and our database can be queried with a call to the lookup method. What our code…

Contents