转载请注明原址:http://write.blog.csdn.net/postedit/52671768
0. 使用环境:eclipse
1. 新建一个测试类
package com.espressif.iot.esptouch.test;
import com.espressif.iot.esptouch.util.CRC8;
import android.test.AndroidTestCase;
@SuppressWarnings("deprecation")
public class JUnitTest extends AndroidTestCase {
public void test() {
int expect = 83;
int real = 82;
assertEquals(expect, real);
}
}
2. AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.espressif.esptouch"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="android.test.runner" />
<activity android:name="com.espressif.iot.esptouch.demo_activity.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="com.espressif.esptouch"
/>
</manifest>
其中,以下两处是为了支持Android JUnit Test添加的:
<uses-library android:name="android.test.runner" />
uses-library 必须添加在application中且与activity平级。
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.espressif.esptouch"
/>
instrumentation与application平级。
3. run as android junit test
参考: