单元测试1(Androidf)
来源:互联网 发布:js为什么禁止跨域请求 编辑:程序博客网 时间:2024/06/14 23:31
步骤:
1.确定要测试的类(MathUtils)方法(incrment)。 --incrment
不能直接在MathUtils类中的main方法直接测试,会有异常,如下:
If you would like to submit a bug report, please visit:
http://java.sun.com/webapps/bugreport/crash.jsp#
2.测试incrment方法,Test类需要继承AndroidTestCase
此时不能测试,测试会有如下错误:
JunitTest does not specify a android.test.InstrumentationTestRunner instrumentation or
does not declare uses-library android.test.runner in its AndroidManifest.xml
3.在清单文件中指定测试信息和要测试的包, 指定引用的测试包
1.
<span style="font-size:14px;">package com.ithema28.junittest.test;import com.ithema28.junittest.utlis.MathUtils;import android.test.AndroidTestCase;public class Test extends AndroidTestCase{ public void test(){//System.out.println("test dsa ");int result = MathUtils.incrment(9, 10);//断言 ,断定某一个对象就是某一个值assertEquals(19, result);}/* JunitTest does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml */}</span>2.
<span style="font-size:14px;">package com.ithema28.junittest.utlis;import android.util.Log;public class MathUtils {/** * 加法运算 * */public static int incrment(int x,int y){/* 这几个BUG依次增强 */Log.v("MathUtils", "黑色:" + x + " + " + y + " = " + (x+y));Log.d("MathUtils","蓝色:" + x + " + " + y + " = " + (x+y));Log.i("MathUtils", "绿色:" +x + " + " + y + " = " + (x+y));Log.w("MathUtils","黄色:" + x + " + " + y + " = " + (x+y));Log.e("MathUtils","红色:" + x + " + " + y + " = " + (x+y));return x+y;}/* 这样测试不对 If you would like to submit a bug report, please visit: http://java.sun.com/webapps/bugreport/crash.jsp# * *//*public static void main(String[] args) {MathUtils m = new MathUtils();int result = m.incrment(1,2);System.out.println(result);}*/}</span>
3.
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ithema28.junittest" android:versionCode="1" android:versionName="1.0" ><!-- 指定测试信息和要测试的包 --> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.ithema28.junittest"></instrumentation> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <!-- 指定引用的测试包 --> <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></manifest>
0 0
- 单元测试1(Androidf)
- Androidf动画-抛物线实现
- 单元测试1
- 单元测试1-为什么需要单元测试
- iOS 单元测试1- 单元测试框架选型
- 单元测试全攻略(1)
- 单元测试初识-1
- 单元测试实践小结1
- 实用单元测试技术(1)
- Android----单元测试 (1)
- 单元测试action -1
- 1、JUnit单元测试
- Android单元测试 Junit(1)
- SilverLight单元测试1:框架
- 单元测试学习1
- Junit4单元测试(1)
- IOS单元测试(1)
- 单元测试
- java.io.FileNotFoundException: /mnt/sdcard/backup.xml: open failed: EACCES (Permission denied)错误解决
- 3pie
- 锋利的jQuery-第三章 jQuery中的DOM操作
- Intellij IDEA 创建Web项目并在Tomcat中部署运行--http://www.thinksaas.cn/group/topic/350000/
- 'ant' 不是内部或外部命令,也不是可运行的程序
- 单元测试1(Androidf)
- php实现冒泡排序,选择排序,插入排序和快速排序
- 转载有关zynq的linux设备树相关知识
- srs/nginx在ubuntu 12.04上面跑得没有问题,可放进centos下面,问题一堆。
- [iOS开发]屏幕适配四:Xcode7使用Autolayout拖拽布局基础(3)TableView自动布局
- OpenGL MV矩阵
- 逃出Chrome沙盒——反Hook技术
- 三天小长假
- python libsvm 使用中问题