Android自动化测试手段之Robotium

本文介绍了一种Android自动化测试方法——Robotium测试,并通过一个具体的示例详细展示了如何使用Robotium-solo-1.6.0.jar来编写自动测试脚本。示例中包括了创建待测项目、设置测试环境、导入必要的库文件以及编写测试代码等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Robotium测试是Android自动化测试的一种手段,闲话不说,直接上示例:

1、首先转创建一个将要被测试的的项目,这里我使用之前自己写的demo进行了一些修改


运行效果如下:


 


2、再创建一个Android Test Project



 
 如上图所示

 

导入robotium-solo-1.6.0.jar

 

编写自动测试脚本,

 

package com.demotest;


import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;

import com.demo.DemoActivity;
import com.demo.R;
import com.jayway.android.robotium.solo.Solo;

public class DemoTest extends ActivityInstrumentationTestCase2 {

	private Solo solo;
	private Activity activity;

	public DemoTest() {
		super("com.demo", DemoActivity.class);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		this.activity = this.getActivity();
		this.solo = new Solo(getInstrumentation(), this.activity);
	}

	@Override
	public void tearDown() throws Exception {
		try {
			this.solo.finalize();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		this.activity.finish();
		super.tearDown();
	}

	/**
	 * @throws Exception
	 *             Exception
	 */
	public void testDisplay() throws Exception {
		String text = "this is robotium test demo";

		// Enter "this is robotium test demo" inside the EditText field.
		this.solo.enterText(R.id.editText, text);
		// Click the button
		this.solo.clickOnButton("Validate");
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值