solo.finishOpenActivities()始终为null

时间:2013-02-11 09:56:59

标签: java android testing robotium

我有一个测试类,但总是在NullPointerException中获得tearDown(),有谁知道为什么?

public class LaunchManagerActivityTest extends ActivityInstrumentationTestCase2<LaunchManagerActivity> {

    private Solo solo;

    public LaunchManagerActivityTest() {
        super(LaunchManagerActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        solo = new Solo(getInstrumentation(), getActivity());
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        solo.finishOpenedActivities();
    }

    public void testOne() {

    }

    public void testTwo() {

    }

1 个答案:

答案 0 :(得分:12)

 @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        solo.finishOpenedActivities();
    }

实际应该是:

 @Override
    protected void tearDown() throws Exception {
        solo.finishOpenedActivities();
        super.tearDown();
    }

超级拆解将关闭已启动的活动,但机器人将因为认为活动已打开而感到困惑,当它尝试对其执行操作时,它为空。