Android的测试:对话框。检查它isShowing() [英] Android Testing: Dialog. Check it isShowing()
问题描述
下面是我的方法,它工作正常,并显示该对话框。
Here is my method, it works fine and shows the Dialog.
public void showDialog(){
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.mylayout);
dialog.show();
}
我有一个测试项目,我想测试该对话框中显示出来。我想申请的.isShowing()方法。事情是这样的......
I have a test project and I would like to test that the Dialog is showing up. I would like to apply the .isShowing() method. Something like this...
assertTrue(dialog.isShowing());
但我不知道怎么去在我的测试中对话变量。
But I don't know how to get to the dialog variable within my test.
我不使用Robotium(这是不是一种选择对我来说)。 我目前使用的ActivityUnitTestCase来测试。如果有任何需要更多的信息,请不要犹豫,问。
I am not using Robotium (this isn't an option for me). I'm currently using the ActivityUnitTestCase to test with. If any more information is required please don't hesitate to ask.
修改
我已经尝试使用下面的答案通过对话框公众
I have attempted to use the answer below by making the Dialog public
public Dialog getDiag(){
return dialog;
}
使用这样的回答:我有一个新的问题,当我在测试中运行的ShowDialog(),它打破当它击中:dialog.show();
Using this answer: I have a new problem when I run showDialog() in the test, it breaks when it hits: dialog.show();
android.view.WindowManager $ BadTokenException:*无法添加窗口 - 标记空
android.view.WindowManager$BadTokenException: * Unable to add window -- token null
推荐答案
声明对话框的ShowDialog函数外,然后实现它返回此对话框实例的方法。
Declare Dialog outside showDialog function and then implement a method which returns this Dialog instance.
public Dialog getDiag(){
return dialog;
}
然后做这样的事情
and then do something like this
assertTrue(new YourClassName().getDialog().isShowing());
这篇关于Android的测试:对话框。检查它isShowing()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!