快速入门:
书中提供VirtualBox虚拟机供学习和尝试书中各种技术。
下载VitrualBox及扩展包,下载虚拟机及虚拟磁盘。Hos机器需要开启Intel VT。
Console中详细展示了Eclipse从启动模拟器到运行应用的完整过程,测试中常用到输出内容来排查错误。
Android系统中,Android自动化单元测试也是一个Android应用工程,它跟普通应用工程不一样的地方就是启动方式不一样。
Eclipse中ADT插件提供了Android自动化单元测试模板。
基类:ActivityInstrumentationTestCase2 单元测试用的是Instrumentation
package cn.hzbook.android.test.chapter1.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.Button;
import cn.hzbook.android.test.chapter1.MainActivity;
import cn.hzbook.android.test.chapter1.R;
public class HelloWorldTest extends ActivityInstrumentationTestCase2<MainActivity> {
public HelloWorldTest() {
super(MainActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
public void firstTestCase() throws Exception {
final MainActivity a = getActivity();
assertNotNull(a);
final Button b = (Button)a.findViewById(R.id.btnAdd);
getActivity().runOnUiThread(new Runnable() {
public void run() {
b.performClick();
}
});
Thread.sleep(5000);
}
}
搭建自动化开发环境;
android create avd -n Android22 -t 1
android list avd
android move avd -n Android22 -p /tmp/Android22
android move avd -n Android22 -r Android2
android delete avd -n Android2
android -h android -h <command>在真机上测试需要再AndroidMainfest.xml中加入可调式,但是在发布前应关闭,一个已发布的应用是不能被调试的。
本文介绍如何使用VirtualBox虚拟机快速搭建Android开发环境,通过Eclipse及ADT插件进行自动化单元测试的实践。内容涵盖下载安装、配置虚拟机、创建测试案例等步骤,并详细展示了在真实设备上的测试流程。
455

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



