AndroidTest

来源:互联网 发布:易语言编程 编辑:程序博客网 时间:2024/05/28 04:54
第一步:在AndroidManifest.xml文件中进行配置, 在manifest节点下配置instrumentation, 在application节点下配置uses-library。如:

<application android:icon="@drawable/icon" android:label="@string/app_name">

<uses-library android:name="android.test.runner"/> 

</application>
<instrumentation
       android:name= "android.test.InstrumentationTestRunner"
       android:targetPackage= "com.cmcc.cmcchyssodemo" />
        ***上面targetPackage指定的包要和应用的package相同。


第二步.:开发测试类
    a) 在com.myapp.test包中创建FileTest类,并继承AndroidTestCase
    b) 声明类属性常量字符串 private static final String TAG = "FileServiceTest";
    c) 编写测试方法testRead(),并在方法内部对FileService实例的read()方法进行测试,如果read()方法有返回值,则取出其返回值,假设返回值赋值到String result变量中
    d) 使用 Log.i(TAG, result) 语句,打印日志,日志级别为i (info),日志标签为TAG常量值,即"FileServiceTest"
3) 测试
     以Android JUnit Test方式运行testRead(),在LogCat视图中通过info级别或TAG筛选查看测试结果
0 0
原创粉丝点击