android - 如何在 Robotium 中检查应用程序是否已完成?

标签 android testing robotium android-lifecycle

我正在尝试使用 Robotium 创建一个测试方法来检查 Android 应用程序是否在单击按钮后完成(在代码中,当用户点击时调用 finish()它)。

public void test_onclickExit_finish() {
    String buttonText = resources.getString(R.string.exit);
    Button exitButton = solo.getButton(buttonText, true);
    solo.clickOnView(exitButton);
    // check here that the app has finished
    // wait for the activity to finish?
    assertTrue(solo.getCurrentActivity() == null);
}

但是这个测试失败了。我不知道如何指示测试等到 Activity 完成。此外,我不确定使用 getCurrentActivity() 是否是检查应用程序是否已完成的好方法。

如何检查应用程序/Activity 是否已完成?

谢谢。

最佳答案

如果这是您的主要 Activity ,请使用:

assertTrue(solo.getCurrentActivity().isFinishing());

关于android - 如何在 Robotium 中检查应用程序是否已完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15418229/

相关文章:

android - Anko 忽略样式中定义的 layout_margin

testing - 当 ATReporter 未对失败的测试进行截图时,如何更改浏览器页面

c# - 我将如何对使用控制台的此 c# 方法进行单元测试?

android - 如何跨多个进程测试 Android 应用程序?

android - 如何知道 robotium 中的对话框已关闭?

java - 如何在文本文件中仅存储唯一条目

java - 字符串迭代和构建新的编码字符串不起作用

android - 将 TextView 放在 ImageView 的中央?

testing - Grails:运行 test-app grails 卸载 lesscss 插件

android - Robotium 搜索 setError 的编辑文本