robotium测试自动例子 androidCalculator

本文介绍了一个计算器应用的自动化测试案例,使用Robotium测试框架验证计算器的功能,包括输入数字、进行运算及验证结果等操作。

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

package com.calculator.test;
import com.calculator.Main;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;


public class CallculatreTest extends ActivityInstrumentationTestCase2<Main> {

private Solo solo;

public CallculatreTest() {
super("com.calculator",Main.class);
}

public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
//该方法用来初始化solo,绑定对应的Activity。
}

//////////////////测试用例


@Smoke
public void testactivity() throws Exception {
assertTrue(solo.searchText("0.0"));
String appname=solo.getCurrentActivity().getLocalClassName();
String expencted= "Main";
assertEquals("类检查正确",appname,expencted);

}
public void testfistnum1() throws Exception {
solo.enterText(0,"123");
boolean expencted= true;
boolean acture=solo.searchText("123");
assertEquals("整型检查正确",expencted,acture);
}

public void testfistnum2() throws Exception {
solo.enterText(0,"asdf");
boolean expencted= true;
boolean acture=solo.searchText("asdf");
assertEquals("字符串检查正确",expencted,acture);
}

public void testsecondnum1() throws Exception {
solo.enterText(1,"123");
boolean expencted= true;
boolean acture=solo.searchText("123");
assertEquals("整型检查正确",expencted,acture);

}

public void testsecondnum2() throws Exception {
solo.enterText(1,"asdf");
boolean expencted= true;
boolean acture=solo.searchText("asdf");
System.out.println(acture);
assertEquals("字符串检查正确",expencted,acture);
}

public void testresult() throws Exception {
solo.enterText(1,"123");
solo.enterText(0, "3");
solo.clickOnButton(0);
assertTrue(solo.searchText("369.0"));
}



@Override
public void tearDown() throws Exception {
try {
//Robotium will finish all the activities that have been opened
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}

}


dos下执行的命令是:adb shell am instrument -w com.example.android.fmcg.test/android.test.InstrumentationTestRunner&

其中com.example.android.fmcg.test是测试的包名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值