与robotium测试活动流程(Testing activity flow with robotiu

2019-10-19 06:23发布

我想用robotium测试一些流

我的流程要经过几次活动,并在中间做一些断言

我的问题是,一旦活动的变化,测试成功结束

如何测试通过几次活动中1个测试走向何方?

我使用robotium 5.0.1

Answer 1:

它很简单的实现。 您可以触发事件,并使用断言一个方法内部API的检查结果

public void testAllActivity(){
    Solo solo = new Solo(getInstrumentation(), getActivity());

    // View1 is a view that is lying in Activity1
    solo.clickOnButton(view1);

    // Put a delay so that you testing with assert doesn't fail.
    solo.waitForActivity("Activity2");
    solo.assertCurrentActivity("<Error Message>","Activity2.class");
    // View2 is a view that is lying in Activity2
    solo.clickOnButton(view1);
    // Put a delay so that you testing with assert doesn't fail.
    solo.waitForActivity("Activity3");
    solo.assertCurrentActivity("<Error Message>","Activity3.class");
}

多数民众赞成它,你在一气呵成完成。



Answer 2:

Robotium应该能够处理交换活动就好了。

您正在使用独奏点击按钮(或图像等...),即

Solo solo = new Solo(getInstrumentation(), getActivity());
//button is a button in activity1 that launches activity2
solo.clickOnButton(button);
//Now we are in Activity2

//otherButton is a button in activity2 that launches activity3
solo.clickOnButton(otherButton);
//Now we are in Activity3

//Check the Current Activity
solo.assertCurrentActivity("Error Message", Activity3.class);

发布一些代码,可能让你更加个性化响应

这也可能帮助: https://groups.google.com/forum/#!topic/robotium-developers/lcneCX_nYPQ



文章来源: Testing activity flow with robotium