当前位置: 代码迷 >> Android >> android单元测试用例跟日志输出
  详细解决方案

android单元测试用例跟日志输出

热度:45   发布时间:2016-05-01 14:33:33.0
android单元测试用例和日志输出
原文地址: http://blog.sina.com.cn/s/blog_694448320100lw0z.html
首先:在AndroidManfest.xml中加入下面粗体代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gohighsoft.unitlog" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<!--下面一行必须要有>
  <uses-library android:name="android.test.runner" />
</application>
<uses-sdk android:minSdkVersion="8" />
<!--下面两行必须要有,不能有错误,targetPackage制定包要和应用的包一致>
<instrumentation android:name="android.test.InstrumentationTestRunner"
  android:targetPackage="com.gohighsoft.unitlog" android:label="Tests for My App" />
</manifest>
说明:
<uses-library android:name="android.test.runner" />改代码必须位于<application>元素之内,与<activity>元素平级
上面targetPackage制定的包要和应用的package相同.如果不相同,会出现找不到单元测试用例的错误
其次:编写单元测试代码
测试类必须继承自AndroidTestCase类
示例代码:
package com.gohighsoft.unitlog;

import junit.framework.Assert;
import android.test.AndroidTestCase;
import android.util.Log;

public class MyTest extends AndroidTestCase {
private static final String TAG = "MyTest";
public void testSave() throws Throwable{
  int i = 4 + 8 ;
  Log.i(TAG, "shuchuxinxi");
  //Assert.assertEquals(12,i);
 
}
}


第三部:执行测试。
自己测试吧
  相关解决方案