Android InstrumentationTestCase在api24中被弃用

Android InstrumentationTestCase在api24中被弃用,android,testing,instrumentation,testcase,Android,Testing,Instrumentation,Testcase,在api24中不推荐InstrumentationTestCase 我可以用什么来代替保持相同的功能 Ex: // Start the MainActivity as the first activity... Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClassName(instrumentation.

在api24中不推荐InstrumentationTestCase

我可以用什么来代替保持相同的功能

Ex:

// 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
的内容,但是函数是完全不同的。

使用类及其方法

getInstrumentation() 返回当前正在运行的检测

您可以使用以下任何方法:

startActivitySync(意图) 启动新活动并等待它开始运行,然后返回

编辑:这是仪器参考链接:

使用类及其方法

getInstrumentation() 返回当前正在运行的检测

您可以使用以下任何方法:

startActivitySync(意图) 启动新活动并等待它开始运行,然后返回


编辑:这是检测参考链接:

谢谢Sara,但是我如何检查当前使用的活动更改是否正确:
currentActivity=getInstrumentation()。waitForMonitorWithTimeout(监视器,超时)
断言(currentActivity,is(notNullValue())getInstrumentation().waitForMonitorWithTimeout(监视器,超时)之后,您会说:
您无法实现您的目标?我可以实现是的,但是使用
InstrumentationTestCase
,我想知道如何为
InstrumentationRegistry
执行此逻辑,因为方法不同。谢谢Sara,但是我如何检查是否有正确的活动更改,我目前使用的:
currentActivity=getInstrumentation().waitFormMonitorWithTimeout(监视器,超时)
断言(currentActivity,is(notNullValue())getInstrumentation().waitForMonitorWithTimeout(监视器,超时)之后,您会说:您无法实现您的目标?我可以实现是,但使用
InstrumentationTestCase
,我想知道如何为
InstrumentationRegistry
实现此逻辑,因为方法不同。