J'utilise "record express test fonction" pour générer le code de test dans android studio 2.2.2 Voici la classe de test générée automatiquement.Exception Android Espresso: android.support.test.espresso.NoMatchingViewException
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mmi.drivemate.R;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.scrollTo;
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.allOf;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class SplashActivityTest {
@Rule
public ActivityTestRule<SplashActivity> mActivityTestRule = new ActivityTestRule<>(SplashActivity.class);
@Test
public void splashActivityTest() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.login_button), withText("SIGN IN"), isDisplayed()));
appCompatButton.perform(click());
ViewInteraction appCompatEditText = onView(
withId(R.id.fragment_login_email));
appCompatEditText.perform(scrollTo(), click());
ViewInteraction appCompatEditText2 = onView(
withId(R.id.fragment_login_email));
appCompatEditText2.perform(scrollTo(), replaceText("safemate2"), closeSoftKeyboard());
ViewInteraction passwordView = onView(
withId(R.id.fragment_login_password));
passwordView.perform(scrollTo(), replaceText("safemate2"), closeSoftKeyboard());
ViewInteraction appCompatButton2 = onView(
allOf(withId(R.id.fragment_login_loginBtn), withText("Login")));
appCompatButton2.perform(scrollTo(), click());
}
}
ci-dessous est mon application gradle:
defaultConfig {
..........
..........
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
dependencies {
.............
.............
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
}
apply plugin: 'com.google.gms.google-services'
J'ai essayé d'utiliser Thread.sleep (1000) dans le cas de test fichier java, le contrôle fonctionne très bien pour les premiers contrôles, mais il se bloque à nouveau lorsqu'une action de vue est effectuée ultérieurement. Y at-il un moyen de résoudre l'exception NoMatchingViewException pour mon cas?
Merci pour la réponse Artem, je essayez votre approche et laissez-vous savoir si cela a fonctionné ou non. –