如何进行单元测试呢?其实也是很简单,只要建一个AndroidTestCase的测试用例就行。
具体方法如下
1、new AndroidProject (新建一个android项目 ,我在这里取名为PersonTestCase)
2、在该项目AndroidManifest.xml文件里面,添加测试需要的配置
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner"/>
<activity
android:label="@string/app_name"
android:name=".MainActivity" >
<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="lzj.junitest.test" android:label="Tests from my App"/>
<uses-library android:name="android.test.runner"/> 一定要加入进去的
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="lzj.junitest.test" android:label="Tests from my App"/>
android:targetPackage 你需要测试的项目的包名
3、new class(这里面主要是该类继承 android.test.AndroidTestCase)
4、填写测试用例
5、在OutLine视图中,启动对应方法,run as --> Android JUnit Application
6、运行完成之后,就会出现JUnit的视图。若是显示红色,说明该测试单元存在问题。绿色测通过了该单元测试。