在android上测试后退按钮时的junit.framework.AssertionFailedError

时间:2013-05-22 04:52:26

标签: android android-activity robotium

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

    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)

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

2 个答案:

答案 0 :(得分:1)

一旦我的一位朋友面临同样的问题,他就会通过提供超时期限来解决问题,同样您没有在waitactivity method中提及超时期限,或者只使用WaitActivity方法而没有timeout argument

希望有所帮助

答案 1 :(得分:0)

这是使用assertTrue(布尔条件)时的预期结果,条件是&#39; False&#39;:

  

public static void assertTrue(boolean condition)

     

断言条件为真。 如果它没有抛出AssertionFailedError。

Android Developers - Assert

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

assertTrue (String message, boolean condition)

- 使用您的自定义字符串消息,您将获得有关哪些内容和哪里出错的信息

assertEquals(true, boolean condition);