android学习笔记5--------------业务bean(单元测试) .
16lz
2021-01-26
android的单元测试非常好用,它可以检测你的功能类或方法是否正确,而不依赖于一些复杂的操作。
单元测试配置:
1.单元测试类继承AndroidTestCase
2.AndroidManifest.xml文件添加
<uses-library android:name="android.test.runner"></uses-library>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.luku.log"//你的包名
android:label="Test for my app"
></instrumentation>
3.测试类编写
例子:
import android.test.AndroidTestCase;import android.util.Log;public class test extends AndroidTestCase{public void add() throws Exception{int i =1+1;xxx();Log.i("test", "结果是="+i);}public String xxx(){String str="输出";int i=1;int x=2;int c=i+x;str=str+c;return str;}}
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.luku.log" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="android.test.runner"></uses-library> <activity android:name=".LogActivity" 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> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.luku.log" android:label="Test for my app" ></instrumentation></manifest>
更多相关文章
- Android(安卓)技术专题系列之十 -- Audio manager
- Android(安卓)网络存储的例子
- Android(安卓)Log日志规则打印
- Android(安卓)appt使用小结
- 编写高效的Android代码(译)
- [置顶] android的logcat详细用法
- adb如何打印kernel输出log
- Android(安卓)IPC机制(Android开发艺术探索)
- Python3原生编写月份计算工具