[Espresso测试标题匹配时得到的字段

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

我正在尝试检查标题和描述textview的值是否与电影标题和描述相匹配,但这是我的第二个测试领域。请帮帮我

我的代码

 @Test
fun test_isTitle_Description_Matches() {
    val movie = INFINITY_WAR
    val fragmentFactory = MovieFragmentFactory()
    val bundle = Bundle()
    bundle.putInt("movie_Id", movie.id)

    val scenario = launchFragmentInContainer<MovieDetailFragment>()
    onView(withId(R.id.movie_title)).check(matches(withText(movie.title)))
    onView(withId(R.id.movie_description)).check(matches(withText(movie.description)))
}
android-espresso
1个回答
2
投票

您已经获得了捆绑软件和片段工厂,但没有传递给片段,请尝试下面的代码。

  @Test
fun test_isTitle_Description_Matches() {
    val movie = INFINITY_WAR
    val fragmentFactory = MovieFragmentFactory()
    val bundle = Bundle()
    bundle.putInt("movie_Id", movie.id)

    val scenario = launchFragmentInContainer<MovieDetailFragment>(
        bundle,
       fragmentFactory
    )
    onView(withId(R.id.movie_title)).check(matches(withText(movie.title)))
    onView(withId(R.id.movie_description)).check(matches(withText(movie.description)))
}
© www.soinside.com 2019 - 2024. All rights reserved.