Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivityScenario: Custom instanciation #433

Open
saschpe opened this issue Aug 30, 2019 · 1 comment
Open

ActivityScenario: Custom instanciation #433

saschpe opened this issue Aug 30, 2019 · 1 comment

Comments

@saschpe
Copy link

saschpe commented Aug 30, 2019

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 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")
@sebokopter
Copy link

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:

ActivityTestRule(SingleActivityFactory<T> activityFactory, boolean initialTouchMode, boolean launchActivity)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants