AndroidTestCase测试用法
1. Java代码TestCase.java 继承AndroidTestCase类
package com.test.casei; import android.test.AndroidTestCase; import android.util.Log; public class TestCase extends AndroidTestCase { private static final String TAG = "TestCase"; @Override protected void setUp() throws Exception { super.setUp(); Log.i(TAG, "[setUp]"); } public void doWorkTest(){ Log.i(TAG, "[doWorkTest]"); } @Override protected void tearDown() throws Exception { super.tearDown(); Log.i(TAG, "[tearDown]"); } }
2. AndroidManifest.xml文件
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.casei" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <uses-library android:name="android.test.runner" /><!-- 为测试添加 android.test.runner--> </application> <!-- 为测试添加 android.test.InstrumentationTestRunner --> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.test.casei" android:label="test" /> </manifest>
3. TestCase.java流程
setup()------>doWorkTest()---->tearDown()