Testing void Methods Using Interactions
As developers adopt a more test-driven style, they learn to avoid writing methods that return nothing. It’s hard to test methods that return void. After all, if nothing is coming back, how do you know those methods worked at all? If you’re lucky, the methods change the state of the object (that is, its contained attributes) and you can check them, but what if that doesn’t happen either? Mockito can help by letting you check the interactions between the class you’re testing and its mocked dependencies.
Let’s introduce a new example involving a popular architecture these days: a publisher/subscriber system, where the publisher sends signals to subscribers that receive them. Publishers and subscribers are ...
Get Mockito Made Clear 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.