当只有一个APK的时候使用robotium进行自动化测试
1. 准备重签名工具:http://www.troido.de/re-sign.jar(在mac上没办法用,只能在windows上用)
3. 搭建测试环境
01
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02
<
manifest
xmlns:android
=
"http://schemas.android.com/apk/res/android"
03
package
=
"com.taobao.taobao.test"
04
android:versionCode
=
"1"
05
android:versionName
=
"1.0"
>
06
07
<
uses-sdk
android:minSdkVersion
=
"8"
/>
08
09
<
instrumentation
10
android:name
=
"android.test.InstrumentationTestRunner"
11
android:targetPackage
=
"com.taobao.taobao"
/>
12
13
<
application
14
android:icon
=
"@drawable/ic_launcher"
15
android:label
=
"@string/app_name"
>
16
<
uses-library
android:name
=
"android.test.runner"
/>
17
</
application
>
18
19
</
manifest
>
01
package
com.taobao.taobao.test;
02
03
import
android.test.ActivityInstrumentationTestCase2;
04
05
import
com.jayway.android.robotium.solo.Solo;
06
07
/**
08
* 测试混淆包
09
*
10
* @author bixiaopeng 2013-4-8 下午1:26:15
11
*/
12
@SuppressWarnings
(
"rawtypes"
)
13
public
class
TestGarblePackage
extends
ActivityInstrumentationTestCase2 {
14
15
private
Solo solo;
16
private
static
Class<?> launchActivityClass;
17
private
static
String mainActivity =
"com.taobao.tao.MainActivity2"
;
// 启动的类名
18
static
{
19
try
{
20
launchActivityClass = Class.forName(mainActivity);
// 通过反射来获取activity
21
}
catch
(ClassNotFoundException e) {
22
throw
new
RuntimeException(e);
23
}
24
25
}
26
27
@SuppressWarnings
(
"unchecked"
)
28
public
TestGarblePackage(){
29
super
(launchActivityClass);
30
}
31
32
@Override
33
protected
void
setUp()
throws
Exception {
34
solo =
new
Solo(getInstrumentation(), getActivity());
35
}
36
37
@Override
38
protected
void
tearDown()
throws
Exception {
39
solo.finishOpenedActivities();
40
}
41
42
public
void
testUpdate()
throws
Exception {
43
solo.clickOnMenuItem(
"检测更新"
);
44
// robotium好像没有直接提供获取toast的方法,所以只用个笨方法
45
int
i =
0
;
46
boolean
toast =
false
;
47
while
(i <
40
) {
48
Thread.sleep(
300
);
49
toast = solo.searchText(
"您使用的版本已是最新的了哦"
);
50
if
(toast) {
51
break
;
52
}
53
i++;
54
}
55
assertEquals(toast,
true
);
56
}
57
}