每个人都使用Robotium进行GUI测试。
你能告诉我Robotium可以做什么Android原生测试框架吗? 据我所知,Robotium可以用作黑盒测试,所以我不需要了解应用程序资源。 还有什么?
答案 0 :(得分:17)
<强> 优点: 强>
<强> 缺点: 强>
android:process
标记用于不同活动的多进程应用程序。示例代码:
<强> 优点: 强>
<强> 缺点: 强>
仅适用于Android 4.1或更高版本!
获取ui-object实例时无法使用源ID。这意味着如果在一个布局上更改了应用程序结构,则需要重构测试(可以通过为每个ui元素使用标记来解决此问题)
您无法获取当前活动或工具。这意味着你在测试开发方面受到限制,并且没有使用许多android的api方法进行测试。
难以调试,您需要有快速建立和开始测试的脚本并查看输出
层次结构查看器:
我认为这两个工具都很好,绝对可以在测试期间在应用程序之间切换是很棒的。您应该根据需要选择工具。我建议Robotium进行测试,你不需要在应用程序之间切换,因为它有简单的方法和机会使用Android API在短代码中编写灵活和智能的测试,甚至可以覆盖webview和milti-process中的网页测试申请非常不寻常。
答案 1 :(得分:7)
Robotium和本机工具之间的区别在于,使用Robotium编写测试非常简单。它基本上是从Solo实例对象中指向并单击。
Here您可以下载JAR文件和示例项目来自行测试。
<强>更新强>
作为一个例子,我正在测试一个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());
}
以下是测试方法:
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);
}
答案 2 :(得分:3)
在android本机的工具框架上使用robotium没有任何缺点。这是因为当使用robotium时,如果没有它,你仍然可以做任何你能做的事情,但你也可以访问许多有用的功能。
还有其他Android自动化框架,但绝对值得一看。如果您在Web视图中有任何代码,这些代码尤其有用,因为这是robotium真正让自己失望的地方。
https://github.com/calabash/calabash-android