Android自动化测试手段之Robotium

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");
	}

}

你可能感兴趣的:(android,python,脚本)