Android 单元测试用法 简介

发表于:2013-8-21 11:05

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Elena_wang    来源:51Testing软件测试网采编

分享:

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

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即可看到运行结果。

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

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

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号