Robotium没有运行所有测试

时间:2012-06-18 22:33:54

标签: java android testing robotium

我有一个我试图运行的Robotium测试套件,由于某种原因它只运行第一次测试,然后冻结。我让程序运行了几分钟,但它只是坐在那里说“测试运行”。这是我的代码:

import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;

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

    public void testLine1(){


        solo.searchText("Easy to Find");        

    }
    public void testLine2(){



        solo.searchText("Hassle-Free");


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

任何帮助都会很棒。谢谢!

这是Junit:

enter image description here

3 个答案:

答案 0 :(得分:1)

你的测试中没有任何断言(虽然我不认为这会是问题)Junit面板在运行时会显示什么?

或尝试:

 public void testLine1(){
    assertTrue(solo.searchText("Easy to Find"));        
 }

答案 1 :(得分:1)

您需要注释测试以作为套件的一部分运行。尝试:

@Smoke
public void testLine1(){
    solo.searchText("Easy to Find");  
}

请记住,您没有在这些测试中声明任何内容,因此它们还不是很有用。您需要添加断言来检查您的代码是否正常运行

答案 2 :(得分:1)

所以我找到了答案:你必须在tearDown()方法中加入solo.finishOpenedActivities();。这将“完成”测试,然后开始新的测试!呼!

感谢所有提供帮助的人!