gpt4 book ai didi

android - 在 ActivityInstrumentationTestCase2 中的 Activity 之前启动服务

转载 作者:行者123 更新时间:2023-11-28 20:24:18 25 4
gpt4 key购买 nike

我正在尝试为我的应用程序编写一些测试。

我的应用程序通过执行业务逻辑的 Service 执行大部分处理。

即使是最小的 Activity 也需要测试,我需要 Service 启动并运行以响应它。

我的问题是,当我没有 Context 时,如何在 ActivityInstrumentationTestCase2setUp() 方法中启动服务从中启动它而不首先调用 getActivity()(这将启动需要服务已经启动的 Activity)。

最佳答案

我想,“getInstrumentation().getTargetContext()”就是您想要的。

关于android - 在 ActivityInstrumentationTestCase2 中的 Activity 之前启动服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16280989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com