Skip to main content

Spying

To create a spy use spy with spied object as a parameter.

warning

Please read limitations section!

val foo = FooImpl()
val spiedFoo = spy<Foo>(foo)

Ensure that you specify a type for the spy. In previous example inferred type would be FooImpl, which is very likely to be a final class, and it is not supported to spy them!

By default, spy delegates all calls to spied object. However, you can change methods behavior in the same way as with mocks.

Read verifying section to learn how to verify calls on spy!