Jim*_*Jim 11 android ui-testing robotium
每个人都使用Robotium进行GUI测试.
你能告诉我Robotium可以做什么Android原生测试框架吗?据我所知,Robotium可以用作黑盒测试,所以我不需要了解应用程序资源.还有什么?
Gen*_*kin 17
优点:
缺点:
android:process用于不同活动的标签的多进程应用程序.示例代码:

优点:
缺点:
仅适用于Android 4.1或更高版本!
获取ui-object实例时,无法使用源ID.这意味着如果在一个布局上更改了应用程序结构,则需要重构测试(可以通过为每个ui元素使用标记来解决此问题)
您无法获得当前活动或仪表.这意味着你的测试开发受到限制,并且没有使用许多android的api方法进行测试.
难以调试,您需要有脚本来快速建立并开始测试并查看输出
层次查看器:

我认为这些工具都很好,绝对有可能在测试期间在应用程序之间切换是非常棒的.您应该根据需要选择工具.我建议Robotium进行测试,你不需要在应用程序之间切换,因为它有简单的方法和机会使用Android API在短代码中编写灵活和智能测试,甚至可以覆盖webview和milti-process中的网页测试应用程序非常不寻常.
Robotium和本机工具之间的区别在于,使用Robotium编写测试非常简单.它基本上是从Solo实例对象中指向并单击.
在这里,您可以下载JAR文件和一个示例项目来自行测试.
UPDATE
作为一个例子,我正在测试一个Activity,其中包含一些Edit Text,一个微调器和一个弹出对话框,当我点击一个微调器选项时它会显示出来.请注意,使用其他方法,填充弹出对话框的字段是一个真正的痛苦.
以下是如何声明测试类和Robotium的初始化
import com.jayway.android.robotium.solo.Solo; //Using Robotium
//Robotium uses ActivityInstrumentationTestCase2.
//Note here the use of the template
public class AddNewQuestionTests extends
ActivityInstrumentationTestCase2<AddNewQuestion> {
public AddNewQuestionTests(Class<AddNewQuestion> name) {
super(name);
}
public AddNewQuestionTests() {
super(AddNewQuestion.class);
}
private Solo solo;
protected void setUp() throws Exception {
super.setUp();
//Initialize Solo with the instrumentation and the activity under test
solo = new Solo(getInstrumentation(), getActivity());
}
Run Code Online (Sandbox Code Playgroud)
这是测试方法:
public void testHappyPathAddScaleQuestion() {
// Type question title
solo.clickOnEditText(0); //find the EditText, and click it
solo.enterText((EditText) getActivity().findViewById(
//find the EditText, and put some string
R.id.activity_add_new_question_editText_question_title),
"Question title scale ");
// Type question description
solo.clickOnEditText(1);
solo.enterText((EditText) getActivity().findViewById(
R.id.activity_add_new_question_editText_question_description),
"Question description scale");
// Type the question
solo.clickOnEditText(2);
solo.enterText((EditText) getActivity().findViewById(
R.id.activity_add_new_question_editText_question),
"Question scale");
// Click the spinner and then the "Scale" question type
//Press an spinner option
solo.pressSpinnerItem(0, 4);
//Wait for the popup dialog title to show up. When robotium reads it, continue working solo.waitForText(getActivity().getResources().getString(R.string.activity_add_new_question_scale_selection_dialog_message));
// Type minimum and maximum ranges
solo.clickOnEditText(0);
solo.searchText(getActivity().getResources().getString(R.string.activity_add_new_question_maximum_value_hint));
solo.clickOnView(solo.getCurrentEditTexts().get(0));
solo.enterText(0, "34");
solo.clickOnView(solo.getCurrentEditTexts().get(0));
solo.enterText(1, "55");
// Click ok to close the dialog
solo.clickOnButton(getActivity().getResources().getString(R.string.OK));
// Click ok to get an ok message
solo.clickOnButton(getActivity().getResources().getString(R.string.OK));
//Wait for the ok toast message
boolean flagOKDatabase=solo.waitForText(getActivity().getResources().getString(R.string.database_success_storing_data),1,120);
assertEquals("Something wrong happened with the database", true, flagOKDatabase);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12091 次 |
| 最近记录: |