【发布时间】:2012-11-01 05:16:51
【问题描述】:
这是我的方法,它工作正常并显示对话框。
public void showDialog(){
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.mylayout);
dialog.show();
}
我有一个测试项目,我想测试对话框是否显示。我想应用 .isShowing() 方法。像这样的...
assertTrue(dialog.isShowing());
但我不知道如何在我的测试中访问对话框变量。
我没有使用 Robotium(这不是我的选择)。 我目前正在使用 ActivityUnitTestCase 进行测试。如果需要更多信息,请随时询问。
编辑
我试图通过公开对话框来使用下面的答案
public Dialog getDiag(){
return dialog;
}
使用这个答案:我在测试中运行 showDialog() 时遇到一个新问题,它在命中时会中断:dialog.show();
android.view.WindowManager$BadTokenException: * 无法添加窗口 -- token null
【问题讨论】:
标签: java android unit-testing reflection dialog