我正在尝试为我的安卓应用添加UI测试,以增加测试覆盖率(我的所有其他层都已经得到了适当的测试,因此现在所有的漏洞都来自于UI...)。
我开始使用ActivityInstrumentationTestCase2
作为我的仿真器单元测试基类,简单的测试很容易检查并且效果很好。
但是现在,我想检查一个对话框是否按预期出现,但我不知道该怎么做。
我的测试:
public void testOpensAboutDialogWhenAboutButtonClicked() {
final MyActivity activity = getActivity();
final Instrumentation instrumentation = getInstrumentation();
final Button aboutButton = (Button) activity.findViewById(R.id.about);
TouchUtils.clickView(this, aboutButton);
// how to test for the AboutDialog?
}
现在我的对话框没有ID,因此我无法使用findViewById获取指向它的指针。 它是使用可用的builder类创建的:
final AlertDialog about = new AlertDialog.Builder(parent)
.setTitle(parent.getString(R.string.about_title))
.setCancelable(true)
.setIcon(R.drawable.skull)
....
任何想法或指向教程的指针?编辑:回答Jens的评论,我没有使用托管对话框,只是创建AlertDialog并使用.show()显示它。