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 theEventBus
and verify that it's called with the correctExceptionEvent
for different inputs.LoginPresenter.onExceptionEvent
: verify correct behaviour for differentExceptionEvents
.EventBus.post
: register a mockedExceptionEvent
-Handler, post anExceptionEvent
and check that the Handler is called.
Post a Comment for "How To/should I Unit Test Eventbus Events With Mockito?"