2017-10-06 3 views

Répondre

1

Essayez ceci:

import static android.support.test.espresso.Espresso.onView; 
import static android.support.test.espresso.action.ViewActions.click; 
import static android.support.test.espresso.assertion.ViewAssertions.matches; 
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 
import static android.support.test.espresso.matcher.ViewMatchers.withId; 
import static android.support.test.espresso.matcher.ViewMatchers.withText; 
import static org.hamcrest.Matchers.not; 

@RunWith(AndroidJUnit4.class) 
public class MainActivityInstrumentedTest { 

    @Rule 
    public ActivityTestRule<MainActivity> mActivityTestRule = 
      new ActivityTestRule<>(MainActivity.class); 

    @Test 
    public void checkTextView_isDisplayed_and_notEmpty() throws Exception { 
     // perform a click on the button 
     onView(withId(R.id.button)).perform(click()); 

     // passes if the textView does not match the empty string 
     onView(withId(R.id.textView)).check(matches(not(withText("")))); 
    } 
} 

Le test ne passera si le textView contient du texte.

+0

Le code ci-dessus fera passer le test lorsque textView est vide. Je veux que le test échoue lorsque textView est vide. Je ne veux pas que ça passe quand c'est vide. –

+0

J'ai mis à jour ma réponse, essayez encore et laissez-moi savoir si cela fonctionne – chornge

+1

oui le code édité ci-dessus travaillé. –