Robotium断言失败 [英] Robotium Assertion Failing

查看:373
本文介绍了Robotium断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行Robotium一个测试,我使用断言来验证是否有在页面上特定的文本,但它失败。然而,当我运行测试没有断言,测试通过。为什么会这样?

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?

下面是我的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();
    }
}

在testLine1测试是失败的考验。但是就像我之前说的,我不使用assertTrue,只是solo.searchTest(容易找到),该测试将通过。我不明白。

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.

感谢您的帮助!

推荐答案

我刚刚发现我试图验证是HTML的内容。如此以来Robotium不与HTML,或任何其他网络组件的工作,也不会验证我正在寻找的文本。

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!

这篇关于Robotium断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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