google-developer-training / advanced-android-testing

Android Testing Codelab
https://codelabs.developers.google.com/codelabs/android-testing/
Apache License 2.0
1.01k stars 677 forks source link

Benfitials of MVP over Event drivven code #54

Closed mehrdad-shokri closed 5 years ago

mehrdad-shokri commented 8 years ago

I'm sorry for creating an issue here maybe it was better to ask it on SO but I hope the creators of project or someone else answers my questions.
I've just become familiar with MVP pattern in android architecture, and packaging your classes over features instead of super classes.
Right now I use event driven architecture (Eventbus) in one of my apps. I was thinking what would be the benefit of using MVP over Event driven.
Using Eventbus I can seperate responsibilty of your methods very easily, So why would one migrate to MVP?
The other question is cant someone please overview the feasibility of using both MVP pattern and Event driven architecture?

The second question is the part you suggest using Dagger for mocking and stubbing, I see that's completely possible using a DI framework. but there's already mocking frameworks like mockito to mock your objects in test code instead of the source code, why should I use dagger in that sense?

dmeng commented 5 years ago

An EventBus-style approach definitely makes sense if anyone calling post() doesn't need to know who is listening, but if the connection between "poster" and "listener" is strict, then that approach can come off as a little "too much" abstraction.

As for discussing the feasibility of using a combination of both MVP and Event-driven architectures, that is a little out-of-scope for this particular codelab. If that's still something you're interested in, maybe take it up with the android architecture guys? I know they have strong opinions on the matter and are actively working on that part of the design phase much easier for developers.

And finally, regarding mocks/stubs, Mockito and related mocking frameworks have places where they're really helpful, but when you're trying to do an integration test with mocks, the setup can get unnecessarily tedious. DI + well-written fakes can make doing that testing possible with less boilerplate.