junit.framework.AssertionFailedError while testing back button on android

浪子不回头ぞ 提交于 2019-12-11 19:13:35

问题


i am new to Robotium.I'm facing an issue "junit.framework.AssertionFailedError" while executing the test case which using Robotium.Test scenario is checking Back button functionality.here's my code

    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();
    }

    }

Here's My error log

[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)

Please let me know if there is any mistake in my code.


回答1:


once one of my friend faced the same problem he resolved by giving timeout period,similarly you haven't mentioned timeout period in waitactivity method or by just using WaitActivity method without timeout argument.

Hope it helps




回答2:


This is the expected result when using assertTrue(boolean condition) and the condition is 'False':

public static void assertTrue (boolean condition)

Asserts that a condition is true. If it isn't it throws an AssertionFailedError.

Android Developers - Assert

Other options that you can use are:

assertTrue (String message, boolean condition)

- with your custom String message you will have information what and where is going wrong

assertEquals(true, boolean condition);


来源:https://stackoverflow.com/questions/16683702/junit-framework-assertionfailederror-while-testing-back-button-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!