当我将项目更新为 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; 红色格式看起来不存在。那么我能在这里做什么——我应该忽略这个吗?