android / android/android-test
ActivityScenario: Custom instanciation
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 2
Description
### 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](https://developer.android.com/guide/navigation/navigation-testing#test_navigationui_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:
See https://issuetracker.google.com/issues/139695101
### Versions
testImplementation("androidx.arch.core:core-testing:2.0.1")
testImplementation("androidx.test.espresso:espresso-core:3.2.0")
testImplementation("androidx.test.ext:junit-ktx:1.1.1")
testImplementation("io.mockk:mockk:1.9.3")
testImplementation("org.robolectric:robolectric:4.3")
Contributor guide
Research direction
Start with the ActivityScenario.launch(Activity) entry point and compare its customization options with launchFragmentInContainer and FragmentScenario. Define how a custom ActivityFactory and optional CREATED or RESUMED initial state should work, then add coverage for custom activity creation and controlled lifecycle state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100