From the course: Programming Foundations: Test-Driven Development

Unlock the full course today

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

Test doubles

Test doubles - Java Tutorial

From the course: Programming Foundations: Test-Driven Development

Start my 1-month free trial

Test doubles

- [Instructor] The system or the object on the test may have external dependencies such as databases, web services or other systems but you may not have access to these external dependencies all the time or they may not even be ready at the time of testing. So the option is to create proxies for these external dependencies or what are formally called as Test Doubles. Test Doubles simulate the behavior of the objects. They are of five different types. A Test Double can be a dummy object, a stub, a fake object, a spy or a mock. Now let's take an example from our hangman game to understand each of these. Let's say there is a requirement to save the game score once the player completes a round. It is also required to keep track of which word is associated with a score. So I have a new method in hangman called saveScore that takes and instance of type WordScore. WordScore has a word and the score associated with it. If you look inside WordScore, there is nothing going on here. I use an…

Contents