当前位置 : 主页 > 网络安全 > 测试自动化 >

Junit4 Android TestField文本测试

来源:互联网 收集:自由互联 发布时间:2021-06-19
我的测试是: @RunWith(AndroidJUnit4.class)@LargeTestpublic class TipActivityTests { @Rule public ActivityTestRuleTipActivity mActivityRule = new ActivityTestRule(TipActivity.class); @Test public void initialValues() { onView(withId(R.
我的测试是:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class TipActivityTests {

    @Rule
    public ActivityTestRule<TipActivity> mActivityRule = new ActivityTestRule<>(TipActivity.class);

    @Test
    public void initialValues() {
        onView(withId(R.id.tip_label_base_price)).check(matches(ViewMatchers.withText("45"")));
    }

}

但是我收到错误’with text:is“45”’与所选视图不匹配.
    预期:带文字:是“45”:

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "45"' doesn't match the selected view.
Expected: with text: is "45"
Got: "AppCompatTextView{id=2131689669, res-name=tip_label_base_price, visibility=VISIBLE, width=266, height=106, 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, root-is-layout-requested=false, has-input-connection=false, x=141.0, y=96.0, text=$45.00, input-type=0, ime-target=false, has-links=false}"

它对我来说没有意义,它不应该打印字段的实际值与比较值?

我遇到了同样的问题,花了很多时间试图了解根本原因.结果证明字符串不等于,这就是它失败的原因.错误消息并不是真正明确的,因为它打印整个对象属性等而不是说:expected:“foo”,收到:“bar”.但实际上比较了字符串.
网友评论