2015-07-07 12 views
5

मेरा परीक्षण है:Junit4 एंड्रॉयड TestField पाठ परीक्षण

@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"' doesn't match the selected view. Expected: with text: is "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}" 

यह dosen't मेरे लिए मतलब है, यह के वास्तविक मूल्य को मुद्रित नहीं करना चाहिए फ़ील्ड बनाम तुलना मूल्य?

उत्तर

2

मुझे एक ही समस्या थी और मूल कारण को समझने की कोशिश करने में काफी समय लगा। यह पता चला कि तार बराबर नहीं थे, यही कारण है कि यह असफल रहा था। त्रुटि संदेश वास्तव में स्पष्ट नहीं है क्योंकि यह कहने के बजाय पूरे ऑब्जेक्ट गुणों को प्रिंट कर रहा है: expected: "foo", received: "bar"। लेकिन तारों की वास्तव में तुलना की जाती है।

+1

हाँ, आप प्रिंट 'text = "real_text" में देख सकते हैं लेकिन यह भयानक है! – Caipivara

संबंधित मुद्दे