1、在进行单元测试前首先必须AndroidManifest.xml中进行配置:
专业领域包括网站制作、做网站、商城网站定制开发、微信营销、系统平台开发, 与其他网站设计及系统开发公司不同,创新互联建站的整合解决方案结合了帮做网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,为客户提供全网互联网整合方案。
(1)<!-- 在根节点 manifest节点下放置 指令集 instrumentation -->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for My App"
android:targetPackage="com.xunfang.junit" />
上面这些代表单元测试的框架的启动装置,启动装置有好几类,默认使用上面的这种。
targetPackage与上面的package相同,为的是使单元测试和当前应用处于同一进程中
(2)<!-- 使用的函数库 application节点的下面-->
<uses-library android:name="android.test.runner" />
代表单元测试的函数库
附上代码:
AndroidManifest.xml中的配置:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<!-- 配置在manifest中 -->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.xunfang.junit" >
</instrumentation>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- 配置在application标签中 -->
<uses-library android:name="android.test.runner"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
上面两段有背景色的是配置全局文件中的配置
业务逻辑中的代码:
public class MyMath {
public int add(int a, int b ){
return a + b;
}
}
单元测试代码:
public class MyJuniteTestCase extends AndroidTestCase {
public void test(){
MyMath my = new MyMath() ;
assertEquals(10, my.add(4, 6)) ;
}
}
测试步骤:
(1) 项目--》右键--》Run As--》Android Jutil Test
(2)打开单元测试代码--》在outLine中选择你要测试的方法--》右键--》Run As--》Android Jutil Test
网页名称:android应用的单元测试
文章URL:https://www.cdcxhl.com/article30/jicdso.html
成都网站建设公司_创新互联,为您提供面包屑导航、商城网站、Google、App开发、电子商务、App设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联