第7章 测 试 方 案
本章包含下面几个主题:
" Android单元测试;
" 测试行为和应用程序;
" 测试数据库和ContentProviders的测试;
" 测试本地和远程服务;
" 测试UI交互;
" 测试异常;
" 测试转换;
" 测试内存泄露。
通过这章学习,你会对测试自己的工程需要干什么,用到什么有一定的了解。
7.1 Android单元测试
我们知道,对工程中的一些组件的测试用例,真的需要在一个独立的,跟底层系统隔离开的环境中才好执行。在执行这些用例的时候,我们要选择一个高权限高层次的类,要可以除去被测模块对其他模块的依赖,但是又不会影响一些基础架构。
对于这个类,我们有个候选类,那就是AndriodTestCase。样例详情可以在Andriod CTS测试集合中下载,如框7.1所示。
框7.1
/* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. * See the License for the specific language governing permissions * and limitations under the License. */ package com.android.cts.appaccessdata; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import android.test.AndroidTestCase; /** * Test that another app's private data cannot be accessed. * * Assumes that {@link APP_WITH_DATA_PKG} has already created the private data. */ public class AccessPrivateDataTest extends AndroidTestCase { /** * The Android package name of the application that owns the private data */ private static final String APP_WITH_DATA_PKG = "com.android.cts.appwithdata"; |
本文选自《Android应用测试指南》第七章,本站经人民邮电出版社和作者的授权。
版权声明:51Testing软件测试网获人民邮电出版社和作者授权连载本书部分章节。
任何个人或单位未获得明确的书面许可,不得对本文内容复制、转载或进行镜像,否则将追究法律责任。