Feature Request: allow custom `Factory` to be passed into `ActivityScenario` (similar to `FragmentScenario`)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with ActivityScenario.java and compare its launch APIs with FragmentScenario.kt's launchInContainer factory support. Trace how ActivityScenario currently creates activities, then identify the API and test changes needed to support custom factories and activity options. Done means custom-constructor activities can be launched with injected dependencies in tests.
Written by the indexing model from the issue text.
Description
Description
API 28 introduced AppComponentFactory. It allows one to provide a custom constructor to any Android component, including an Activity. Most apps cannot utilize this feature due to the minimum API requirement. For those that can, defining a custom constructor for an Activity means that there may be no empty default constructor available.
That complicates the usage of ActivityScenario: it doesn't support a Factory parameter to provide custom dependencies (see here).
To address this issue, I propose that ActivityScenario should support a Factory parameter, similar to FragmentScenario (see here). This would enable developers to take full advantage of providing custom dependencies during tests:
val scenario = launchActivity(
activityOptions, // we likely want to support activity options.
factory = { MyCustomActivity(Deps1(), Deps2()) } // where factory is a `() -> Activity` or similar.
)
Steps to Reproduce
- Create an app using API 28 or above.
- Create a custom
AppComponentFactory. - Create an
Activityusing a custom constructor. - Try to write a test using the custom constructor providing custom dependencies in the test, similar to Fragments: Provide Dependencies.
Expected Results
Similar to FragmentScenario, ActivityScenario should support custom dependencies.
Actual Results
There is no way to provide custom dependencies without modifying the whole AppComponentFactory of the tests or using workaround (i.e., leaving the Activity as an open class and provide a custom implementation in the test).
AndroidX Test and Android OS Versions
Current version: 1.5.0
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 7
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from android/android-test
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
android/android-test#681 · 2 comments · 1 reaction ·
-
ξεκσνδξδOpen
Difficulty 5/5 Over a week Newbie friendliness 1/100
android/android-test#2499 ·
-
ησξξσOpen
Difficulty 5/5 Over a week Newbie friendliness 1/100
android/android-test#2498 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
android/android-test#2473 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
android/android-test#2461 · 6 comments · 4 reactions ·
All issues in android/android-test
Similar issues
-
1.0.0-rc2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#377 ·
Maintainers usually reply within 1 day
-
area/dependencies backport/26.4 kind/cve severity/high source/scan-dependencies status/triage
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
(primitive-collections-base) Use `NumberInput` to parse numeric map keys, as `jackson-databind` doesOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
FasterXML/jackson-datatypes-collections#270 ·
Maintainers usually reply within 1 day
-
type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day