活动不符合Robotium不同的测试重启 [英] Activity doesn't restart in different tests with Robotium

查看:294
本文介绍了活动不符合Robotium不同的测试重启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试我的应用程序与Robotium登录,我有一些问题。我有两个不同的用户类型,所以我做了3次试验。一个用于每个类型和另一个登录失败。如果我执行他们的个人都成功,但如果我运行所有它运行一个测试用例,执行拆解(solo.finishOpenedActivities),它不重新启动的活动执行等测试。所以在第二次测试时,我问了它的EditText说,是不可用的。

I'm testing my app's Login with Robotium and I'm having some problems. I've got two different user types so I've made 3 tests. One for each type and another failed login. If I execute them individually they all success, but if I run all the test case it runs one, executes the tearDown(solo.finishOpenedActivities) and it doesn't restart the activity to execute the other tests. So in the second test when I'm asking for a EditText it says that is not available.

下面是我的code:

public class TestLogin extends ActivityInstrumentationTestCase2<MainActivity> {

private Solo solo;

public TestLogin() {
    super("com.truekke4.test", MainActivity.class);
}

@Override
protected void setUp() throws Exception {
    solo = new Solo(getInstrumentation(), getActivity());
    super.setUp();
}

@Override
public void tearDown() throws Exception {
    getActivity().logout();
    solo.finishOpenedActivities();
    super.tearDown();
}

public void testUsuarioDesconocido() {
    solo.clearEditText(0);
    solo.enterText(0, "usuario desconocido");
    solo.assertCurrentActivity("Error", MainActivity.class);
    solo.clickOnButton("OK");
    solo.clickOnButton("OK");
    solo.assertCurrentActivity("Error", MainActivity.class);
}

public void testUsuario() {
    solo.clearEditText(0);
    solo.enterText(0, "usuario");
    solo.clickOnButton("OK");
    solo.assertCurrentActivity("Error", InicioUsuarioActivity.class);
}

public void testEmpresa() {
    solo.clearEditText(0);
    solo.enterText(0, "empresa");
    solo.clickOnButton("OK");
    solo.assertCurrentActivity("Error", InicioPymeActivity.class);
}

}

我必须手动重新启动该活动?创建和意图和startActivity(意向)?

I've got to restart the activity manually? Create and Intent and startActivity(intent)?

我没有完成开活动?或者,我必须完成的活动,但重新启动它们/它设置()。我怎么能重新启动或创建活动,使recognizeables为Robotium?

I don't have to finish opened activities? Or I have to finish activities but restart them/it in setUp(). How Can I restart or create activities to make recognizeables for Robotium?

帮助!

推荐答案

我相信正在引起您的问题,因为你重写设置()从ActivityInstrumentationTestCase2方法,而比使用Robotium方法。在你的测试类,Robotium查找与签名公共无效设置()的方法来配置它的测试,这可能会比较混乱,因为它具有相同的名称的方法是不能修改的。我不知道究竟何时或如何往往是受保护的设置被称为,但我知道,公众一个是作为Robotium保证每个测试之前调用它来初始化独奏的最佳场所。尝试改变:

I believe your issue is being caused because you're overriding the setUp() method from ActivityInstrumentationTestCase2 rather than using the Robotium method. In your test classes, Robotium looks for a method with the signature public void setUp() to configure its tests, which can get confusing, because it has the same name as the method that can be overridden. I'm not sure of exactly when or how often the protected setUp is called, but I know that the public one is the best place to initialize solo as Robotium is guaranteed to call it before each individual test. Try changing:

@Override
protected void setUp() throws Exception

public void setUp() throws Exception

用同样的方法体(但没有@Override注释),看看是否允许您运行所有测试。

with the same method body (but without the @Override annotation) and see if that allows you to run all your tests.

这篇关于活动不符合Robotium不同的测试重启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆