January 2018
Intermediate to advanced
434 pages
14h 1m
English
The mocking framework also provides a spy method that can be used to wrap the real objects. The calls to the spy objects are delegated to the real object. What's the use of that, you might be thinking. It can check the interactions on a real object, which wasn't possible if the object is not mocked. Let's take a look at the following example:
@Testfun testSpyObject(){ val list = List(2,init = {-1}) val spy= spy(list) assertEquals(spy.get(0),-1) verify(spy).get(0)}
The preceding test will pass.
Note that calling spy.get(0) returns -1, which is equal to what you'd get if you had interacted with the real object. Furthermore, you are also able to verify the interaction.
Read now
Unlock full access