Android中的JUnit测试 - DialogFragment [英] JUnit testing in Android - DialogFragment

查看:324
本文介绍了Android中的JUnit测试 - DialogFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中,当pressed应该打开一个DialogFragment一个FragmentActivity的按钮。

I have a button in a FragmentActivity which, when pressed should open a DialogFragment.

我要测试它使用的作品为Android的JUnit在Eclipse。

I want to test that it works using JUnit for Android in Eclipse.

与活动我可以使用活动监视器。如何测试即单击按钮时正确的片段已经打开?

With an Activity I could use ActivityMonitor. How can I test that the correct Fragment has opened when the button is clicked?

推荐答案

假设你喜欢这样的打开你的对话片段:

Assuming you are opening your dialog fragment sort of like this:

DialogFragment dlg = YourDialogFragment.newInstance(..);
dlg.show(getFragmentManager(), "yourDialogTag");

您可以检查它的向上和在你的测试用例这样显示:

you can check that it's up & showing by doing this in your test case:

// Click stuff on the UI-thread
getInstrumentation().waitForIdleSync();
Fragment dialog = getActivity().getFragmentManager().findFragmentByTag("yourDialogTag");
assertTrue(dialog instanceof DialogFragment);
assertTrue(((DialogFragment) dialog).getShowsDialog());

这篇关于Android中的JUnit测试 - DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆