This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
[Feature request] Attaching a view without calling onAttachView()
#132
Labels
onAttachView()
#132
I came across this while writing presenter tests with the help of Mockito.
Imaging you have the following code in your presenter:
And you've written a test that verifies that
showLoading()
was actually called on your view:Now you want to add a new method to the Presenter (for example
onClick()
) that also should callview.showLoading()
and add a second test that verifies this behavior:Now comes the tricky part:
This test will pass even if the method
onClick()
has an empty body!How can this be?
Since ThirtyInch enforces you to attach the view to your Presenter before you can retrieve it (which is fine from a logical standpoint) it always calls
onAttachView()
which causes your Presenters implementation to be executed.Normally you want the scope of your test as small as necessary which means for the example of
showLoading()
that you only want to verify what happens inonClick()
. But here is the issue with Mockito because the interactions with your mocks are recorded and every time you are done with your test setup (which includes attaching the view to the Presenter)onAttachView()
was called as well. This forces you to either verify that some method was called multiple times (which is not good in my opinion because it enlarges the scope of your test) or it enforces you to reset your mock (which is not so good as well because it can easily be missed to reset all mocks that already have interactions inonAttachView()
especially in a grown Presenter implementation).And in case you are using
RxTiPresenterSubscriptionHandler
to add a managed subscription inonAttachView()
it gets even more complicated to test.Since we already use
TiPresenterInstructor
in our tests to "instruct" the Presenter to attach a View. Wouldn't it be nice to have a way to bypass theonAttachView()
-callback if you don't need it in your test?tl;dr:
I would love to see a way to setup the presenter for tests without
onAttachView()
being called.The text was updated successfully, but these errors were encountered: