I have an android test checking that external text message is truncated and ends with three dots when applying android:ellipsize=\"end\". I do not know why test fails despite te
To check if the text of a TextView has been ellipsized you can create your custom matcher like this one:
fun ellipsized() = object : TypeSafeMatcher() {
override fun describeTo(description: Description) {
description.appendText("with ellipsized text")
}
override fun matchesSafely(v: View): Boolean {
if (!(v is TextView)) {
return false
}
val textView: TextView = v
val layout: Layout = textView.getLayout()
val lines = layout.lineCount
if (lines > 0) {
val ellipsisCount = layout.getEllipsisCount(lines - 1)
if (ellipsisCount > 0) {
return true
}
}
return false
}
}
And call it this way:
onView(withId(R.id.errorMessageTextView))
.check(matches(ellipsized()))