“ androidx.test.espresso.NoMatchingViewException:在片段中找不到与ID匹配的分层视图”

问题描述 投票:0回答:1

我尝试了几个堆栈溢出问题来解决此问题。我附上该日志,以供参考,如下所示:

androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.gzw.presentation.fragment:id/count_view

在我的Testcase类中,我是这样写的:

@Before
public void setUp() throws Exception {
    mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    activityRule.getActivity()
            .getSupportFragmentManager().beginTransaction();

}

在另一种测试方法中,我正在检查片段布局视图中的UI元素。

 @Test
public void testInitializedViews() {

    Espresso.onView(withId(R.id.count_view)).check(matches(isDisplayed()));

}

这里R.id.count_view是textview驻留在片段布局中。如果有人知道如何在片段布局视图中使用espresso。在这里让我知道...

注意:google / stackoverflow链接均无法解决此问题。

android android-fragments junit android-espresso
1个回答
0
投票

您应使用FragmentScenario.launchInContainer()方法,此链接可以帮助您:https://github.com/robolectric/robolectric/issues/5157

© www.soinside.com 2019 - 2024. All rights reserved.