2015-07-07 12 views
5

La mia prova è:Junit4 Android TestField prova testo

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

} 

ma ho l'errore di '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}" 

E dose non ha senso per me, non dovrebbe stampare il valore effettivo di il campo rispetto al valore comparato?

risposta

2

Ho avuto lo stesso problema e ho trascorso un po 'di tempo cercando di capire la causa principale. Risultò che le stringhe non erano uguali, ecco perché stava fallendo. Il messaggio di errore non è esplicito in quanto stampa tutte le proprietà dell'oggetto ecc. Invece di dire: expected: "foo", received: "bar". Ma le stringhe sono effettivamente confrontate.

+1

Sì, è possibile vedere nella stampa 'text =" real_text "' ma è orribile! – Caipivara

Problemi correlati