robolectric/robolectric — pull request #1124 by erichaugh (2014-06-04 17:19:24+00:00)
Title: Add ActivityController launch().

I submitted a previous pull request for the same change (https://github.com/robolectric/robolectric/pull/1119#issuecomment-45047197), and closed it when it was pointed out to me that Robolectric.setupActivity() exists. I realize now though setupActivity() doesn't do what I need, because it doesn't give a chance to set dagger-injected dependencies on the Activity before calling the lifecycle methods. I.e., a common pattern in my test code is:

ActivityController activityController = Robolectric.buildActivity(SomeActivity.class);
// set dagger injected fields on the Activity
activityController.get().someDependency = mockSomeDependency;
activityController.create()....

There's an argument to be made against adding too many convenience methods, but in my particular case it would help alleviate some boilerplate.

I also like the idea of it being convenient to call every lifecycle method that Android calls as a matter of course - if the Activity is modified to override a new lifecycle method that breaks something, there is more hope the existing tests will catch it.