小编Muh*_*lan的帖子

我将现有项目更新为 androidx 但得到了 ExampleInstrumentedTest--> getTargetContext 错误

当我将项目更新为 androidx 时,出现以下错误

我也搜索过但找不到我的答案,尽管项目运行良好

@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.example.villagefoodsecrets", appContext.getPackageName());
    }
}
Run Code Online (Sandbox Code Playgroud)

此时,@RunWith(AndroidJUnit4.class)表明它已被弃用。

Context appContext = InstrumentationRegistry.getTargetContext(); .getTargetContext; 红色格式看起来不存在。那么我能在这里做什么——我应该忽略这个吗?

android androidx

8
推荐指数
1
解决办法
1812
查看次数

标签 统计

android ×1

androidx ×1