Android JUnit Test for Eclipse使用入门

来源:互联网 发布:mac微信接收的文件 编辑:程序博客网 时间:2024/04/30 16:26

转载请注明原址: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);}}

其中,test方法可以改成任意以test开头的public void testXXX方法。也可以有多个不同的。


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


参考:

http://blog.csdn.net/hjd_love_zzt/article/details/9141451

http://www.myexception.cn/ai/1232887.html

0 0
原创粉丝点击