Skip to content Skip to sidebar Skip to footer

How To/should I Unit Test Eventbus Events With Mockito?

I use Otto's EventBus in my Android app. In my LoginNetworkOperation class, I catch different kinds of network connection errors and I post different bus events for each one, and m

Solution 1:

My question is how (and should I) do I unit test whether the LoginNetworkOperation throws this event and LoginPresenter handles it with Mockito?

That's already an integration test: you're combining individual software modules and verifying their behaviour as a group.

In that case the "subject under test" is the combination of LoginNetworkOperation, EventBus and LoginPresenter and the mocked objects are the inputs to LoginNetworkOperation and whatever handles the output of LoginPresenter.


Those three software modules can also be unit tested:

  • LoginNetworkOperation.execute: mock the EventBus and verify that it's called with the correct ExceptionEvent for different inputs.
  • LoginPresenter.onExceptionEvent: verify correct behaviour for different ExceptionEvents.
  • EventBus.post: register a mocked ExceptionEvent-Handler, post an ExceptionEvent and check that the Handler is called.

Post a Comment for "How To/should I Unit Test Eventbus Events With Mockito?"