Mocking for integration tests

Great question.

It seems like you hit the limits of Mockito. Mockito is great if what you want to inspect object interactions.

What you want, though, seems to be observability (and controllability) at a higher level of abstraction. I’m afraid that the mocks or stubs you need for that should be carefully designed and hand-crafted.

At the unit level, these mocks can be nicely generated, by means of Mockito. At the integration level, this becomes much harder, and you will need purpose made testability interfaces.

Leave a Comment