2015-07-07 21 views
5

Benim testtir:Junit4 Android test alanı metin testi

@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""))); 
    } 

} 

Ama hatayı 'with text: is "45"' doesn't match the selected view. Expected: with text: is "45" olsun: Bu bana mantıklı doesnt

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}" 

, bu gerçek değerini yazmak yerine, alan karşılaştırılan değer vs?

cevap

2

Aynı problemi yaşadım ve kök nedenini anlamaya çalışmak için biraz zaman harcadım. Dizeleri eşit değildi ortaya çıktı, bu yüzden başarısız oldu. Hata iletisi gerçekten açık değildir çünkü expected: "foo", received: "bar" yerine tüm nesne özelliklerini vs yazdırıyor. Ama dizeler aslında karşılaştırıldı.

+1

Evet, print = text = "real_text" 'yazısını görebiliyorsunuz ama bu korkunç! – Caipivara

İlgili konular