检查 activity 是否打开或崩溃 mockito

Check activity is opened or crashed mockito

这个问题是关于android单元测试MVP
在测试 class 中,我需要调用演示者 class

中的 openactivity 方法

并且该方法将使用 view.openCheckoutShippingActivity() 方法打开 activity。
如何使用 mockito

检查它是否打开

您不能对 Android 特定元素执行单元测试。您应该使用仪器化测试。这些测试 运行 在设备或模拟器上进行。 Android的官方插桩测试框架是Espresso。实际上这很容易。一个例子:

@Test
fun greeterSaysHello() {
    onView(withId(R.id.name_field)).perform(typeText("Steve"))
    onView(withId(R.id.greet_button)).perform(click())
    onView(withText("Hello Steve!")).check(matches(isDisplayed()))
}

来自官方文档。

关于您的具体问题,请参考this link

还要小心,这测试 运行 在 androidtest 包下,而不是在 test 包下。

编辑

i need to call openactivity method which is in presenter class and that method will open an activity

我不确定你做的对不对。 activity 应该从 View 打开,而不是从 Presenter.

打开