Robotium测试是Android自动化测试的一种手段,闲话不说,直接上示例:
1、首先转创建一个将要被测试的的项目,这里我使用之前自己写的demo进行了一些修改

运行效果如下:

2、再创建一个Android Test Project
如上图所示
导入robotium-solo-1.6.0.jar
编写自动测试脚本,
package com.demotest;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import com.demo.DemoActivity;
import com.demo.R;
import com.jayway.android.robotium.solo.Solo;
public class DemoTest extends ActivityInstrumentationTestCase2 {
private Solo solo;
private Activity activity;
public DemoTest() {
super("com.demo", DemoActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
this.activity = this.getActivity();
this.solo = new Solo(getInstrumentation(), this.activity);
}
@Override
public void tearDown() throws Exception {
try {
this.solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
this.activity.finish();
super.tearDown();
}
/**
* @throws Exception
* Exception
*/
public void testDisplay() throws Exception {
String text = "this is robotium test demo";
// Enter "this is robotium test demo" inside the EditText field.
this.solo.enterText(R.id.editText, text);
// Click the button
this.solo.clickOnButton("Validate");
}
}
本文介绍了一种Android自动化测试方法——Robotium测试,并通过一个具体的示例详细展示了如何使用Robotium-solo-1.6.0.jar来编写自动测试脚本。示例中包括了创建待测项目、设置测试环境、导入必要的库文件以及编写测试代码等步骤。
111

被折叠的 条评论
为什么被折叠?



