网上的notepad.apk示例,只有apk的情况下自动化
1、从源码打包一个APK
2、对apk重新签名,package name和Main Acitivyt如图
3、将apk安装到手机后,启动测试
报错:Test run failed: Instrumentation run failed due to 'Process crashed.'
网上找了很多都没有得到解决;
后来发现,重新签名后,给出的Main Acitivyt不太对,查看源码发现层级中少一个点,加上后变成com.example.android.notepad.NotesList,再运行,不报这个错了。
package com.robotium.test;
import org.junit.Test;
import android.test.ActivityInstrumentationTestCase2;
import com.robotium.solo.Solo;
//rawtypes是说传参时也要传递带泛型的参数
@SuppressWarnings("rawtypes")
public class GralleryTest extends ActivityInstrumentationTestCase2 {
// private static String packageName = "com.xiaomi.channel";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.example.android.notepad.NotesList";
private static Class<?> launcherActivityClass;
static{
try{
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
}
catch(ClassNotFoundException e){
throw new RuntimeException(e);
}
}
// 告知系统我要测试的app是什么
//J2SE 提供的最后一个批注是 @SuppressWarnings。该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默。
//这个只是一个注解,通知编译器在编译时不进行检查,比如在类型转换时
@SuppressWarnings("unchecked")
public GralleryTest() throws ClassNotFoundException{
//launcherActivityClass要测试的类
super(launcherActivityClass);
System.out.println(1111);
}
private Solo solo;
//打开gallery
//用来初始设置,如启动一个Activity,初始化资源等
public void setUp() throws Exception {
super.setUp();
//getInstrumentation()初始化solo
solo = new Solo(getInstrumentation(),getActivity());
// Log.v(LAUNCHER_ACTIVITY_FULL_CLASSNAME, "setUp()");
}
public void testAddNote() throws Exception {
}
public void tearDown() throws Exception {
//tearDown() is run after a test case has finished.
//finishOpenedActivities() will finish all the activities that have been opened during the test execution.
//即关闭应用程序
//不知道为什么不需要清理
//solo.finishOpenedActivities();
}
}