0

我是Robotium的新手。我在执行使用Robotium的测试用例时遇到问题“junit.framework.AssertionFailedError” 。测试场景正在检查后退按钮功能。这是我的代码

    package com.example.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;

import com.jayway.android.robotium.solo.Solo;
import com.example.app.R;
import com.example.app.LoginActivity;
import com.example.app.AccountCardListActivity;
import com.example.app.ReceiptListActivity;
import com.example.app.WithdrawalListActivity;


public class Back_Concerto_425 extends ActivityInstrumentationTestCase2<LoginActivity>{




    public Back_Concerto_425() {
        super(LoginActivity.class);
        // TODO Auto-generated constructor stub
    }


    private Solo solo;


    protected void setUp() throws Exception
    {
        solo = new Solo(getInstrumentation(), getActivity());

    }

    public void testbackbutton()
    {

        solo.enterText(0, "username");
        solo.enterText(1, "password");
        solo.clickOnButton(0);
        solo.waitForActivity("com.example.app.WithdrawalListActivity", 3000);
        assertTrue(solo.searchText("WithdrawlListActivity"));
        solo.clickOnButton("View Receipts");
        solo.waitForActivity("com.example.app.ReceiptListActivity",3000);
        assertTrue(solo.searchText("Receipts"));
        solo.goBackToActivity("com.example.app.WithdrawalListActivity");
        assertTrue(solo.searchButton("View Receipts"));
        assertTrue(solo.searchButton("New withdrawal"));


    }


    public void tearDown() throws Exception
    {

        try
        {
            solo.finalize();
        }
        catch (Throwable e)
        {
            e.printStackTrace();
        }

        super.tearDown();
    }

    }

这是我的错误日志

[INFO]     Start [15/16]: com.ncr.mobile.mcw.test.WithdrawlListActivityTest#testreceiptsbutton
[INFO]     FAILURE:com.ncr.mobile.mcw.test.WithdrawlListActivityTest#testreceiptsbutton
[INFO]     junit.framework.AssertionFailedError
at com.ncr.mobile.mcw.test.WithdrawlListActivityTest.testreceiptsbutton(WithdrawlListActivityTest.java:45)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)

如果我的代码有任何错误,请告诉我。

4

2 回答 2

1

一旦我的一个朋友遇到了同样的问题,他通过给出超时时间来解决,同样你没有提到超时时间waitactivity method或者只是使用WaitActivity没有的方法timeout argument

希望能帮助到你

于 2013-05-28T05:04:31.487 回答
0

这是使用 assertTrue(boolean condition) 且条件为“False”时的预期结果:

公共静态无效断言真(布尔条件)

断言条件为真。如果不是,它会抛出一个 AssertionFailedError。

Android 开发者 - 断言

您可以使用的其他选项包括:

assertTrue (String message, boolean condition)

- 使用您的自定义字符串消息,您将了解问题所在和位置

assertEquals(true, boolean condition);
于 2015-06-30T10:58:21.953 回答