#android #android-espresso
#Android #android-эспрессо
Вопрос:
Я пишу тестовые примеры Эспрессо для сценария, в котором я хочу передать намерение в действие. извлеките значение из намерения и установите его в textview.
@RunWith(AndroidJUnit4::class) class DetailFragmentTest { @Before fun setUp() { Intents.init() } @After fun cleanUp() { Intents.release() } @Test fun test_view_visibility() { launchActivitylt;DetailActivitygt;() onView(withId(R.id.text_title)).check(matches(isDisplayed())) } @Test fun test_view_matches() { val intent = Intent(ApplicationProvider.getApplicationContext(), DetailActivity::class.java) intent.putExtra(AppConstants.TITLE, "Testing") launchActivitylt;DetailActivitygt;(intent) onView(withId(R.id.text_title)).check(matches(isDisplayed())) } }
Тестовый пример test_view_visibility() пройден, однако функция test_view_matches() завершается ошибкой с
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: view.getId() is lt;2131362768/com.example.android:id/text_order_id_titlegt; View Hierarchy: gt;DecorView{id=-1, visibility=VISIBLE, width=1024, height=107, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params={(0,0)(wrapxwrap) gr=CENTER sim={adjust=pan} ty=APPLICATION fmt=TRANSPARENT wanim=0x7f130005 fl=DIM_BEHIND ALT_FOCUSABLE_IM SPLIT_TOUCH HARDWARE_ACCELERATED fitTypes=STATUS_BARS NAVIGATION_BARS CAPTION_BAR}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1} | -gt;LinearLayout{id=-1, visibility=VISIBLE, width=1024, height=107, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@c9f457e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} | --gt;ViewStub{id=16908719, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@4712adf, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} | --gt;FrameLayout{id=-1, visibility=VISIBLE, width=1024, height=107, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@92ed1f5, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1} | ---gt;FitWindowsFrameLayout{id=2131361849, res-name=action_bar_root, visibility=VISIBLE, width=1024, height=107, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@bef8618, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} | ----gt;ContentFrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=1024, height=107, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@af48656, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1} | -----gt;ConstraintLayout{id=-1, visibility=VISIBLE, width=1024, height=107, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@8c4aad, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} | ------gt;ProgressBar{id=2131362524, res-name=progress_view, visibility=VISIBLE, width=107, height=107, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@94ab1e2, tag=null, root-is-layout-requested=false, has-input-connection=false, x=459.0, y=0.0} | ------gt;AppCompatTextView{id=-1, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@dccc973, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Loading…, input-type=0, ime-target=false, has-links=false} | ----gt;ViewStubCompat{id=2131361868, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@7850030, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} at dalvik.system.VMStack.getThreadStackTrace(Native Method) at java.lang.Thread.getStackTrace(Thread.java:1736) at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:12) at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:7) at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:8) at androidx.test.espresso.ViewInteraction.check(ViewInteraction.java:12) at com.example.details.fragment.DetailFragmentTest.test_view_matches(DetailFragmentTest.kt:96)
Разница между этими двумя методами в том, что я передаю намерение в действие. Любые предложения о том, как решить эту проблему, помогут
Комментарии:
1. Почтовый индекс
launchActivity
иonCreate
, по крайней мере, ваша деятельность.