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/