Summary
In this chapter, we’ve looked at how to solve the problem of testing problematic collaborators. We have learned how to use stand-in objects for collaborators called test doubles. We’ve learned that this gives us simple control over what those collaborators do inside our test code.
Two kinds of test double are especially useful to us: the stub and the mock. Stubs return data. Mocks verify that methods were called. We’ve learned how to use the Mockito library to create stubs and mocks for us.
We’ve used AssertJ to verify the SUT behaved correctly under the various conditions of our test doubles. We’ve learned how to test error conditions that throw exceptions.
These techniques have expanded our toolkit for writing tests.
In the next chapter, we are going to cover a very useful system design technique that allows us to get most of our code under FIRST unit test, and at the same time avoid the problems of testing collaborations with...