Feature Request: allow custom `Factory` to be passed into `ActivityScenario` (similar to `FragmentScenario`)
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
调研方向
从 ActivityScenario.java 开始,将其启动 API 与 FragmentScenario.kt 对 launchInContainer 的 factory 支持进行比较。跟踪 ActivityScenario 当前如何创建 activity,然后确定支持自定义 factory 和 activity 选项所需的 API 和测试更改。当测试能够启动具有自定义构造函数并注入依赖项的 activity 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Java
- 星标
- 1.2k
- 派生
- 344
- 平均合并
- 3 天 2 小时
- 30 天内合并 PR
- 5
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
android/android-test 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 62/100
android/android-test#681 · 2 条评论 · 1 个 reaction ·
-
ξεκσνδξδ未关闭
难度 5/5 一周以上 新手友好度 1/100
android/android-test#2499 ·
-
ησξξσ未关闭
难度 5/5 一周以上 新手友好度 1/100
android/android-test#2498 ·
-
难度 4/5 3-5 天 新手友好度 38/100
android/android-test#2473 ·
-
难度 4/5 3-5 天 新手友好度 25/100
android/android-test#2461 · 6 条评论 · 4 个 reaction ·
查看 android/android-test 的全部 Issue
相似的 Issue
-
status: waiting-for-triage
难度 2/5 1-3 小时 新手友好度 79/100
spring-projects/spring-ai#7206 ·
维护者通常 2 天内回复
-
bug ci sev-6
难度 2/5 1-3 小时 新手友好度 73/100
-
area/cli
难度 2/5 半天 新手友好度 78/100
quarkusio/quarkus#57623 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
jhipster/prettier-java#1113 ·
维护者通常 2 天内回复
-
bug follow-up lane:backlog
难度 2/5 1-3 小时 新手友好度 82/100
Sanne/incus-spawn#1576 · 1 条评论 ·
维护者通常 1 天内回复