单元测试(对项目中某一个独立业务模块进行单独的测试)
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" >
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中出现第二个运行结果)
相关文章推荐
- Android WebView使用全面解析(加载网络资源、本地HTML,JS交互)
- untiy3d-socket简单应用
- Android缓存机制介绍:一个缓存框架推荐
- mybatis动态sql中的trim标签的使用
- C#提示框代码
- 并发新特性—阻塞队列与阻塞栈
- 【整理】1到n的数字典序排序(N为long long)
- 计算两个日期之间的工作日(去掉周末和节假日)
- 分布式事务——使用消息队列消除两阶段提交
- centos6.5 安装linux 环境
- USB枚举详细过程剖析(转)
- iOS移动开发周报-第24期
- 对话框自带滚动条的使用
- C#线程类Thread初步
- 支付宝接入
- 关于HTTP请求出现 405状态码 not allowed的解决办法
- Openstack 之 ceilometer: Alarm
- Maintaining Consumer Groups, Plans, and Directives
- Bootstrap progress-bar
- Leetcode-12. Integer to Roman