本文介绍了测试某个按钮开始在Android中的JUnit(不robotium preF)一项新的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法找到任何这很好的帮助。我有一个在短短几个按钮一个简单的活动,我需要测试,如果他们重新定向到正确的新页面(活动)。
I cant find any good help on this. I have a simple activity with just a few buttons on and I need to test if they re-direct to the correct new page (activity).
public void testButton() {
button.requestFocus();
button.performClick();
}
我真的不知道不止于此。本教程都非常无益的在做这个:/
I really have no idea beyond that. The tutorials are all very unhelpful in doing this :/
推荐答案
您需要的,它可以帮助你在改编期间moniotor新开张的活动,检查出的伪code如下:
You need ActivityMonitor, it helps you moniotor newly opened activity during instrumentation, check out the pseudo code below:
public void testOpenNextActivity() {
// register next activity that need to be monitored.
ActivityMonitor activityMonitor = getInstrumentation().addMonitor(NextActivity.class.getName(), null, false);
// open current activity.
MyActivity myActivity = getActivity();
final Button button = (Button) myActivity.findViewById(com.company.R.id.open_next_activity);
myActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
// click button and open next activity.
button.performClick();
}
});
//Watch for the timeout
//example values 5000 if in ms, or 5 if it's in seconds.
NextActivity nextActivity = getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5000);
// next activity is opened and captured.
assertNotNull(nextActivity);
nextActivity .finish();
}
这篇关于测试某个按钮开始在Android中的JUnit(不robotium preF)一项新的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!