android - api 24 中不推荐使用 Instrumentation 测试用例

标签 android testing instrumentation testcase

InstrumentationTestCase 在 api24 中已弃用

What could I use to replace keeping the same functions?

例如:

// Start the MainActivity as the first activity...
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName(instrumentation.getTargetContext(), MainActivity.class.getName());
    instrumentation.startActivitySync(intent);

我已经阅读了一些关于InstrumentationRegistry的东西,但是功能却大不相同。

最佳答案

使用类 IntstrumentRegistry从它的方法

getInstrumentation() Returns the instrumentation currently running.

您可以使用任何方法,例如:

startActivitySync(Intent intent) Start a new activity and wait for it to begin running before returning.

编辑:这是检测引用链接:https://developer.android.com/reference/android/app/Instrumentation.html

关于android - api 24 中不推荐使用 Instrumentation 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47350739/

相关文章:

java - 来自除主布局之外的其他布局的小部件上的空指针异常

android - 更新到 4.0 后无法在 Android Studio 中创建 Activity 或 Fragment

c# - Selenium Webdriver - 如果未在 Debug模式下运行,则测试失败断言 C# visual studio

ruby-on-rails - stub ActiveRecord 结果数组

macos - OSX 上的 clang : -finstrument-functions link errors

java - 如何让ZXing在android中的部分 Activity (而不是全屏)中显示?

具有多种颜色主题的 Android 小部件

xcode - 是否可以在 XCode 中使用两台 iPad 测试我的应用程序?

java - 检测 System.setProperty 方法调用

c# - 将我的 Web 应用程序从 .Net 3.5 升级到 .Net4.0 后,出现安全透明规则失败