Android学习系列-单元测试与程序调试(5)
2013-08-19 21:01
423 查看
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.关键点
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.
相关文章推荐
- android学习笔记(9)android程序调试学习
- Android程序开发学习笔记系列——基础篇(附源码)
- 程序调试 -- MarsChen Android 开发教程学习笔记
- Android程序开发学习笔记系列——基础篇(附源码)
- android 怎么进行调试程序 如何采用AndroidTestCase进行单元测试
- Android学习系列(29)--App调试的几个命令实践
- Android学习系列(32)--App调试内存泄露之Cursor篇
- android 学习笔记(五) 调试相关 5.1 android使用wifi进行程序调试
- Android开发学习笔记6--安卓程序调试方法
- Android学习之三:使用DDMS调试程序
- Android学习-好马配好鞍,程序真机调试运行
- Android学习系列(36)--App调试内存泄露之Context篇(上)
- Android学习系列--App调试内存泄露之Context篇(下)
- 羊皮书APP(Android版)开发系列(九)通过Wifi调试程序
- Android学习系列--App调试内存泄露之Context篇(上)
- Android学习系列(29)--App调试的几个命令实践
- Android 开发系列:Android eclipse中程序调试
- android学习笔记(9)android程序调试学习
- android加固系列—2.加固前先要学会破解,调试内存值修改程序走向
- android调试系列--使用ida pro调试原生程序