Exploring a test spy
A spy secretly obtains the information of a rival or someone very important. As the name suggests, a spy object spies on a real object. A spy is a variation of a stub, but instead of only setting the expectation, a spy records the method calls made to the collaborator. A spy can act as an indirect output of the unit under test and can also act as an audit log.
We'll create a spy object and examine its behavior; the following are the steps to create a spy object:
- Launch Eclipse, open
<work_space>, and go to the
- Create a
com.packt.testdoubles.spypackage and create a
StudentServiceclass. This class will act as a course register service. The following is the code for the