Robolectric测试中的“java.lang.AssertionError:预期可见但不可见”

时间:2014-07-16 01:33:46

标签: android unit-testing robolectric

为什么以下测试会因标题中给出的错误而失败?

@RunWith(RobolectricTestRunner.class)
public class MainActivityTest {

    private MainActivity mActivity;

    @Before
    public void setUp() {
        mActivity = Robolectric.buildActivity(MainActivity.class).create().get();
    }

    @Test
    public void testBaseballCardDetails() {
        FragmentManager fm = mActivity.getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(FragmentTags.EDIT_CARD);

        assertThat(fragment).isNotNull().isAdded().isVisible();
    }

}

1 个答案:

答案 0 :(得分:0)

我似乎需要在visible()上致电ActivityController

mActivity = Robolectric.buildActivity(MainActivity.class).create().visible().get();