android / android/android-test
ActivityScenario: Custom instanciation
- Vorherrschende Sprache
- Java
- Sterne
- 1.2k
- Forks
- 342
- Ø Merge
- 11 Std. 29 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
### 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")
Beitragsleitfaden
Rechercherichtung
Beginne mit dem Einstiegspunkt ActivityScenario.launch(Activity) und vergleiche seine Anpassungsoptionen mit launchFragmentInContainer und FragmentScenario. Definiere, wie eine benutzerdefinierte ActivityFactory und ein optionaler initialer Zustand CREATED oder RESUMED funktionieren sollen, und füge anschließend Abdeckung für die Erstellung benutzerdefinierter Activities und einen kontrollierten Lifecycle-Zustand hinzu.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- android, java
- Bereich
- mobile, testing
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100