java测试:
package com.exaple.test;
import com.example.service.CalcService;
import android.test.AndroidTestCase;
public class TestCacle extends AndroidTestCase {
public void testAdd() throws Exception{
CalcService service = new CalcService();
int result = service.add(3, 5);
//断言测试
assertEquals(8, result);
}
}
AndroidManifest.xml配置:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.junit"
android:versionCode="1"
android:versionName="1.0" >
<!--
指令集:
instrumentation:测试时必须配置这个指令
-->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.junit"
></instrumentation>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!--i测试时:使用函数库 -->
<uses-library android:name="android.test.runner"/>
<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>
</application>
</manifest>