每当我在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);
}
}