Android学习系列-单元测试与程序调试(5)
1.关键点
1)AndroidManifest.xml中必须配置如下节点
<uses-library android:name="android.test.runner" />

<instrumentation android:name="android.test.InstrumentationTestRunner"

android:targetPackage="cn.nt.test" android:label="Test for MyApp" />


2)AndroidManifest.xml完整代码
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="cn.nt.test"

android:versionCode="1"

android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">

<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>

<uses-library android:name="android.test.runner" />

</application>

<uses-sdk android:minSdkVersion="8" />

<instrumentation android:name="android.test.InstrumentationTestRunner"

android:targetPackage="cn.nt.test" android:label="Test for MyApp" />


</manifest>
3)单元测试类必须继承自AndroidTestCase
例如:public class LogTest extends AndroidTestCase{
public void testSave() throws Exception{
PersonService service = new PersonService();
service.save(null);
}

public void testAdd() throws Exception{
PersonService service = new PersonService();
int actual = service.add(1, 2);
Assert.assertEquals(8, actual);//测试结果会在单元测试窗口中显示
}


}

2.程序调试输出信息
private static final String TAG = "LogTest";

public void testOutLog() throws Throwable{
Log.i(TAG, "www.baidu.cn");
}

public void testOutLog5() throws Throwable{
Log.i(TAG, "123456");
}

public void testOutLog2() throws Throwable{
System.out.println("www.csdn.com");
}

public void testOutLog3() throws Throwable{
System.err.println("www.163.com");
}
输出信息在Logcat窗口中能够看到。
信息分类级别debug<info<warn<error.


更多相关文章

  1. android中退出整个app应用程序
  2. Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android(安
  3. android系统移植琐碎知识整理:
  4. android通过google API获取天气信息
  5. Android进行数字签名的方法
  6. Android(安卓)Intent用法汇总
  7. Android(安卓)让一个Service开机自动启动
  8. Android(安卓)下载
  9. android获取手机信息2

随机推荐

  1. Android(安卓)1.5 SDK与SDK开发教程
  2. android开发技巧
  3. [Android]网络资源下载时断点续传的实现
  4. 关于android OpenGl ES 渲染方式
  5. 请告诉美工Android适配时切图要按标准来
  6. Android的Linux内核的电源管理:Early Susp
  7. 有哪些 Android(安卓)大牛的 blog 值得推
  8. 关于android的webview屏幕适应
  9. Android(安卓)异步任务 设置 超时使用han
  10. Android(安卓)编译中的LOCAL_SDK_VERSION