- 浏览: 46589 次
- 性别:
- 来自: 西安
最新评论
android
Testing and Instrumentation
Key features of the Android testing environment include:
Android extensions to the JUnit framework that provide access to Android system objects.
An instrumentation framework that lets tests control and examine the application.
Mock versions of commonly-used Android system objects.
Tools for running single tests or test suites, with or without instrumentation.
Support for managing tests and test projects in the ADT Plugin for Eclipse and at the command line
下面实现一个简单的测试程序、
你的负责测试的程序是通过在其manifest 文件中<instrumentation> 标签来把待测试的程序连接到一起
The attributes of the element specify the package name of the application under test and also tell
<instrumentation> 的属性确定了待测试的程序的包名,并告诉Android 如何去运行这个测试程序 Instrumentation 更详细
的描述了Instrumentation Test Runner.
Eclipse with ADT provides an extensive set of tools for creating tests, running them, and viewing their results. You can also use the adb tool to run tests, or use a built-in Ant target.
在android中测试程序和android 程序的写法是一样的。SDK tools 帮助你同时创建 main application project and its test project。你可以在eclipse中用ADT 或是
用命令行还完成测试。你可以参考Testing in Eclipse 去学习怎样在eclipse中编写和运行测试程序
接下来的Hello, Testing tutorial 将会介绍一些基本的测试概念
在这个例子中你将会学习android程序开发的基本原理。这个例子将会引导你用ADTsetup一个android的测试项目。
Creating the Test Project
In the Hello World tutorial you created Android application project called HelloAndroid. A test of an Android application is
also an Android application, and you create it within an Eclipse project.
The Eclipse with ADT New Android Test Project
dialog creates a new test project and the framework of a new test application at the same time.
待测程序源代码
the activity:
public class HelloTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
下面是maim.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
string.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World!</string>
<string name="app_name">HelloAndroidTest</string>
</resources>
按如下步骤创建一个test project
In Eclipse, select New > Project > Android > Android Test Project.
The New Android Test Project dialog appears.
Set the following values:
Test Project Name: "HelloAndroidTest"
Test Target: Set "An existing Android project", click Browse, and then select "HelloAndroid" from the list of projects.
Build Target: Set a target whose platform is Android 1.5 or above.
Application name: "HelloAndroidTest"
Click Finish. The new project appears in the Package Explorer.
然后Creating the Test Case Class
The basic structure includes all the files and directories you need to build and run a test application, except for the class
that contains your tests (the test case class).
现在你有一个test project 叫HelloAndroidTest 这个项目中最基本的结构都已经帮你创建好了,你只需要自己创建一个Test Case Class, 这个类当中
将会包含你想要做的测试
The next step is to define the test case class. In this tutorial, you define a test case class that extends one of
Android's test case classes designed for Activities. The class contains definitions for four methods:
HelloAndroidTest: This defines the constructor for the class. It is required by the Android testing framework.
setUp(): This overrides the JUnit setUp() method. You use it to initialize the environment before each test runs.
testPreconditions(): This defines a small test that ensures the Hello, Android application starts up correctly.
testText(): This tests that what is displayed on the screen is the same as what is contained in the application's
string resources. It is an example of a real unit test you would perform against an application's UI.
下面这个test case 是测试界面上显示的 android:text="@string/hello"的内容是否和string.xml资源文件中的内容一样
public class HelloAndroidTest extends ActivityInstrumentationTestCase2<HelloAndroid> {
private HelloAndroid mActivity;
private TextView mView;
private String resString;
/**
* @param pkg
* @param activityClass
*/
public HelloAndroidTest() {
super("hust.ophoneclub.HelloAndroid",HelloAndroid.class );
// TODO Auto-generated constructor stub
}
@Override
protected void setUp() throws Exception {
super.setUp();
// initialize variables and prepare the test environment.
mActivity = this.getActivity();
mView = (TextView)mActivity.findViewById(hust.ophoneclub.HelloAndroid.R.id.textview);
resString = mActivity.getString(hust.ophoneclub.HelloAndroid.R.string.hello);
}
public void testPreconditions() {
//A preconditions test checks the initial application conditions prior to executing other tests
assertNotNull(mView);
}
public void testText() {
assertEquals(resString, (String) mView.getText());
}
}
发表评论
-
Android Intent and Intent Filter (转)
2011-03-10 22:47 1431Android Intent and Intent ... -
Intent详解
2011-03-03 14:18 1118在应用中,我们可以以两种形式来使用Intent: 直接I ... -
Intent间传送数据一般有两种常用方法
2011-01-24 14:50 1276Intent间传送数据一般有两种常用的办法: 1.extra ... -
android RelativeLayout 详解
2011-01-01 09:46 1563<?xml version="1.0" ... -
How to Use Android Downloads Provider
2010-12-20 21:41 1311本文转载自 http://blog.lytsing.or ... -
android 开发中的一些小知识点
2010-12-17 09:49 9651 关于onPause(): onPause ... -
content provider 深入解析
2010-12-15 22:04 1073Content providers are on ... -
Service的高级应用
2010-12-12 20:48 1325下面是android Service的高级应用的一个例子,主要 ... -
TabActivity
2010-12-12 19:09 1737下面是一个使用android tabactivity 的例子 ... -
Localization of android
2010-12-05 21:51 0android 会在不同地域的不同机器上运行。为了是应用能够 ... -
android高效编程之使用本地变量
2010-12-05 14:26 950hava a look at the following co ... -
在不同的Activity中传递对象的方法
2010-12-02 10:20 1982下面我们将要实现的功 ... -
Cursor与Adapter
2010-11-21 08:34 1206来自: http://hi.baidu.com/lfcaoli ... -
Working with Context Menus
2010-11-15 23:36 830... -
Handler的理解
2010-11-14 20:58 803A Handler allows you to sen ... -
android开发问题解决日志
2010-11-14 18:33 18501.、android中R文件消失的处理方式 ... -
android 中对SDCard 的操作
2010-11-11 14:14 1601对于像视频这样的大文件,我们可以把它存放在SDCard。 SD ... -
ViewAnimation
2010-11-05 12:46 1014view animation 的实现 Understandi ... -
android高效的编写高效代码
2010-10-17 19:13 730本文来源于: 从此学习网 原文: http://www.con ... -
scale animation
2010-10-11 23:29 1588Scale animation: You use this t ...
相关推荐
学习Android有一段时间了,虽然前段时间对软件测试有了一些了解,不过接触android的单元测试却是头一次。这几天在物流大赛上也用了不少时间,所以对于android的单元测试没有太深入的研究,所以先写个基本入门吧!...
android自动化测试初探 InstrumentationTestRunner
Android自动化测试初探 简单介绍了android自动化测试的方法,给入门者提供思路!
Android自动化测试初探
初探Android初探Android
3.Create_Android_Sample_...Android自动化测试初探 Android自动化测试可行性途径分析 Android自动化测试之道 GSM手机自动化测试解决方案 手机自动化测试系统设计浅析 在Android_Robotium自动化测试中导出Test_result
ArcGIS Runtime SDK for Android开发介绍,来自Esri 中国技术人员的培训材料。
Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明 Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明 Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明
Android fragment懒加载初探
Kotlin初探与集成Android项目
Android Apk解密工程初探
Android_Sensor传感器系统架构初探
“药材盈”电子商务软件测试初探.doc
入门--初探Android,对Android的初步介绍。
1.初探Android 2.Android开发环境搭建与编译 3.Android编译过程分析 4.android.mk初识 5.Android.mk学习1 6.Android.mk学习2 7.Android.mk学习3 8.Android启动课程大纲 9.Android启动模式 10.init启动分析 11.走入...
基于Scrum的Android教学改革初探.pdf
这个是我在华为进行培训自己写的ppt,欢迎下载.
关于android AppWidget初探① http://blog.csdn.net/zhq56030207/archive/2010/08/13/5809535.aspx#1631197
selenium+junit+hudson自动化测试初探