一、修改配置文件AndroidManifest.xml
<? xml version="1.0" encoding="utf-8" ?> < manifest xmlns:android ="http://schemas.android.com/apk/res/android" package ="cn.ycmoon.test.activity" android:versionCode ="1" < uses-sdk android:minSdkVersion ="8" /> < application android:icon ="@drawable/icon" android:label ="@string/app_name" > < 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 > < instrumentation android:name ="android.test.InstrumentationTestRunner" android:targetPackage ="cn.ycmoon.test.activity" android:label ="Testing" /> </ manifest > |
说明:1、在Application节点中Activity前添加 <uses-library android:name="android.test.runner" />
2、在Application节点的添加 <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="cn.ycmoon.test.activity" android:label="Testing" />
二、在相应包中编写要完方法,
三、在src同级级目录中添加一个test文件夹[可自定义],并在下建立和项目一致的包名: cn.ycmoon.test.activity 四、在要进行单元测试的方法上右键->NEW->JUNIT Test Case。弹出下界面: 选择 SuperClass为: