ActivityInstrumentationTestCase2 getActivity()永不返回

时间:2013-08-13 23:30:46

标签: android unit-testing android-testing

每当我在Android测试项目中运行所有测试时,我的一个测试永远不会完成。使用LogCat,我已将问题缩小到getActivity()方法。我还将Log.d()放在ViewAllSongsActivity.onCreate()中,但邮件从未打印过。当我单独运行ViewAllSongsActivityTests时,测试通过。以下是测试代码:

public class ViewAllSongsActivityTests extends ActivityInstrumentationTestCase2<ViewAllSongsActivity> {
    public ViewAllSongsActivityTests() {
        super(ViewAllSongsActivity.class);
    }

    public void testSongsAreLoaded() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Activity activity = this.getActivity(); // this never returns
        ListView songList = (ListView) activity.findViewById(R.id.allSongsList);
        assertTrue(songList.getCount() > 0);
    }
}

0 个答案:

没有答案