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 the3605OS_TestDoubles
project. - Create a
com.packt.testdoubles.spy
package and create aStudentService
class. This class will act as a course register service. The following is the code for theStudentService
class:public ...
Get Mockito Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.