Robotium Assertion Failing

百般思念 提交于 2020-02-05 09:03:13

问题


When I run a test with Robotium, I use an assertion to verify that there is specific text on the page, but it fails. However, when I run the test without the assertion, the test passes. Why would this be?

Here is my code:

import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;

@SuppressWarnings("unchecked")
public class ODPRobotiumTest extends ActivityInstrumentationTestCase2 {

    private static final String TARGET_PACKAGE_ID = "com.gravitymobile.app.hornbill";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.vzw.odp.LaunchActivity";

    private static Class<?>launcherActivityClass;

    static{
        try{
            launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e){
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings({ "unchecked", "deprecation" })
    public ODPRobotiumTest() throws ClassNotFoundException{
        super(TARGET_PACKAGE_ID, launcherActivityClass);
    }

    private Solo solo;

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

    @Smoke
    public void testLine1(){

        try {
            assertTrue(solo.searchText("Easy to Find")) ;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
    @Smoke
    public void testLine2(){


            try{
        solo.searchText("Hassle-Free");
            }catch(Exception e){
                e.printStackTrace();
            }

    }
    @Smoke
    public void testLine3(){




        solo.searchText("Trust");


    }
    public void testLine4(){

        solo.searchText("Verizon Curated Wallpaper");


    }
    public void testLine5(){

        solo.searchText("Taco's");

    }
    @Override
    public void tearDown() throws Exception{
        try{
            solo.finalize();
        }catch(Throwable e){
            e.printStackTrace();
        }
        getActivity().finish();
        super.tearDown();
    }
}

The test in testLine1 is the test that fails. But like I said before, when I don't use the assertTrue, and just solo.searchTest("Easy to find"), the test will pass. I don't understand.

Thanks for any help!


回答1:


If you don't assert anything then your test will pass cause nothing can fail.

Obviously the text you are searching is either missing from the screen, your configuration of the test runner is wrong or you are not even using the correct mechanisms for searching.




回答2:


I just found out the content that I am trying to verify is HTML. So since Robotium doesn't work with HTML, or any other web component, it won't verify the text I'm looking for.

Thank you to all who offered help!



来源:https://stackoverflow.com/questions/11092407/robotium-assertion-failing

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