getActivity在ActivityUnitTestCase中返回null

时间:2015-10-08 13:15:59

标签: android android-testing

如果getActivity()总是返回null,如何在android测试中获取活动?

public class PageDistrListTest extends ActivityUnitTestCase<PageDistrList> {

PageDistrList activity;

  @Override
  protected void setUp() throws Exception {
        super.setUp();
        activity = getActivity();
        headerRecycler = (RecyclerView) activity.findViewById(R.id.page_tab_distr_recycler_header);
    }
}

1 个答案:

答案 0 :(得分:1)

您将获得此类活动实例

activity = launchActivity("package.PageDistrList", PageDistrList.class, null);

我不确定。请随时纠正我。