Я пытаюсь проверить один из моих операторов, пытающийся проверить, показывает ли мой textView заголовок объекта, который я передаю в намерении, но я не могу его получить. Всегда есть эта ошибка:
E/TestRunner: androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "this is title post"' doesn't match the selected view.
Expected: with text: is "this is title post"
Это мой тест:
class DetailActivityTest{
@Rule
@JvmField
var activityRule = ActivityTestRule<DetailActivity>(DetailActivity::class.java, true, false)
@Before
@Throws(Exception::class)
fun setUp() {
val intent = Intent()
intent.putExtra(DetailActivity.DETAIL, mockedPostDataViewModel())
activityRule.launchActivity(intent)
}
@Test
fun check_intent_is_received_and_show_elements(){
onView(withId(R.id.txPostTitleDetail)).check(matches(withText("this is title post")))
}
}
fun mockedPostDataViewModel(): PostDataViewModel{
return PostDataViewModel(
"this is a body post",
1,
"this is title post",
UserViewModel("email", 1, "email", "bob spencer"),
ComentViewModel())
}
private fun ComentViewModel(): List<CommentViewModel>{
val comment = CommentViewModel(1)
return listOf<CommentViewModel>(comment)
}