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

Unlock this course with a free trial

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

Creating a mock

Creating a mock

- [Instructor] So, I'd like to now create two further tests. The first one will be testing that, if there's matching data in the database, then we use the database version. So, let's call this one databaseIsUsedIfDataIsPresent(), and I'll just put the call to the fail() method in here for the moment. And the second one that we're going to write, is going to be the opposite, which is webserviceIsUsedIfDataIsNotPresent. Actually, let's make this even clearer, let's put at the end of here, InDatabase. And again, we'll call the fail() method for now, and I'm just going to run this code, and make sure that we have now one passing test, and two failing tests. Okay, that looks good. Now, I could create code in these two methods that's very similar to this test here, and that would work for this first one. If we pot a book in the database version, and not in the webService version, but we know the code works, well, we know the database version was used. And we could to the opposite, and make…

Contents