You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The launch(Activity) method can't be customized very well, especially compared to launchFragmentInContainer / FragmentScenario. That makes it particularly hard to test / verify code that happens during onCreate(). In our example, a MainActivity (that contains the NavHostFragment for Jetpack Navigation) navigates to an on-boarding screen on first start.
Verifying this code is hard with the current ActivityScenario as the initial state can't be controlled and thus we can't properly mock / spy the navigation controller (Compared to how it can be done with FragmentScenario).
Expected Results
Ideally, launch(Activity) take a custom ActivityFactory or Lambda like launchFragmentInContainer that allows to customize activity creation. A convenience parameter to decide which state to launch into (i.e. CREATED, RESUMED) won't hurt either.
Link to a public git repo demonstrating the problem:
I want to second @saschpe : Having a custom/intercepting Activity factory allows for providing test instances via a constructor instead of exposing a public setter only for testing.
ActivityTestRule has a constructor with an SingleActivityFactory interface:
Since ActivityTestRule is marked deprecated are there any plans to (re-)introduce this behavior to ActivityScenarionRule? Or would you at least welcome a PR?
Zemotacqy
pushed a commit
to Zemotacqy/android-test
that referenced
this issue
May 5, 2023
Description
The
launch(Activity)
method can't be customized very well, especially compared to launchFragmentInContainer / FragmentScenario. That makes it particularly hard to test / verify code that happens during onCreate(). In our example, a MainActivity (that contains the NavHostFragment for Jetpack Navigation) navigates to an on-boarding screen on first start.Verifying this code is hard with the current ActivityScenario as the initial state can't be controlled and thus we can't properly mock / spy the navigation controller (Compared to how it can be done with FragmentScenario).
Expected Results
Ideally,
launch(Activity)
take a customActivityFactory
or Lambda likelaunchFragmentInContainer
that allows to customize activity creation. A convenience parameter to decide which state to launch into (i.e. CREATED, RESUMED) won't hurt either.Link to a public git repo demonstrating the problem:
See https://issuetracker.google.com/issues/139695101
Versions
The text was updated successfully, but these errors were encountered: