qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

Android 单元测试用法 简介

本代码中只简单写了一个类,可以在该类中增加想要测试的功能项。

Focus2AndroidTest测试类
package com.example.aaaaa;
import android.test.AndroidTestCase;
public class Focus2AndroidTest extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
System.out.println("====aaaa====");
}
}

  AndroidManifest.xml中需要增加几个属性

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="com.example.aaaaa"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="7" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.aaaaa.Focus2AndroidTest"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="android.test.runner" />//增加的第一个位置
</application>
<uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />//增加的第二个位置
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Test for my app"
android:targetPackage="com.example.aaaaa" />
</manifest>

  运行程序时与正常的运行部太一样。右键功工程名->run as->android jUnit test即可看到运行结果。

  注意包名等地方要与当前工程名相一致。

  运行结果:(右侧的东西为正常运行后的内容)

posted on 2013-08-22 11:14 顺其自然EVO 阅读(223) 评论(0)  编辑  收藏 所属分类: android


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年8月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜