我想在Android上编写一个Expresso测试来验证TextView内容。 当我读从资源文本如下它的工作原理Espresso - 验证TextView内容Android
@Test
public void changeText_newActivity() {
onView(withId(R.id.mainContent)).check(matches(withText("Hello World!")));
}
以上是用咖啡 下面的测试是在Android上的活动代码在那里工作
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainContent"
android:text="@string/hello_world"
/>
但是当我替换文本使用硬编码文本而不是引用资源测试失败,并获取错误无法找到视图层次结构中的视图
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainContent"
android:text="Hello world!"
/>
以下是我运行测试时的错误
android.support.test.espresso.NoMatchingViewException:层次结构中没有视图找到匹配项:与文本:是“Hello world!”
提前赞赏您的帮助。