您的位置:首页 > 其它

单元测试(对项目中某一个独立业务模块进行单独的测试)

2016-09-30 09:53 435 查看
1.创建一个单元测试的测试案例(AndroidTestCase)

2.要在清单文件中进行相关的配置(基本可以提示出来)

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<span style="color:#6633ff;"> <!-- 配置单元测试引用的包 -->
<uses-library android:name="android.test.runner"/></span>
<activity
android:name="com.example.karen.youlu.SplashActivity"
android:label="@string/app_name" >
</application>

<span style="color:#6600cc;"><instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.day_01" >
</instrumentation></span>

</manifest>
3.创建相应的类进行测试(继承AndroidTestCase类,并且自定义方法名为:test)
public class MyTestCase extends AndroidTestCase{

public void test(){
List<Contact> contacts = ContactManager.getContacts(getContext());
for (Contact contact : contacts) {
Log.i("tag", contact.toString());
}
}
}
(将需要测试的内容放入test方法中,运行光标指示的部位,在DDMS中出现第二个运行结果)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: