Posts

Showing posts with the label xUnit

Introduction to Test Doubles with Mockito

It is not uncommon to encounter a situation when the System Under Test (SUT) is dependent on a number of collaborators. Let's imagine that we are developing code that emulates an Automatic Teller Machine (ATM). An ATM can be thought of as a box that host various components such as the keyboard, the display, the cash dispenser and so on, as well as it is a controller that orchestrates the work of constituent parts. In addition, it should have a communication link to the bank it belongs, in order to check user's details and the state of her account. There is a lot of parts that may not be already produced by the time we write the ATM class and also if they were, it could be slow to use real parts in our tests. Moreover, an attempt to communicate with the bank could lead to unpredictable and not repeatable results. Furthermore, it is easier to emulate communication failures with some code than with hardware. To solve a problem of testing a system which is dependent on other...