私はアンドロイドスタジオ2.2.2のテストコードを生成するために "レコードエスプレッソテスト機能"を使用しています 以下は自動生成テストクラスです。以下はAndroidのエスプレッソ例外: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());
}
}
私のアプリの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'
私はテストケースのjavaファイルでのThread.sleep(1000)を使用してみました、コントロールは最初の数チェックのために細かい動作しますが、それは再びクラッシュ後でビューアクションが実行されるときに発生します。 私の場合、NoMatchingViewExceptionを解決する方法はありますか?
おかげで、私は意志あなたのアプローチを試し、それがうまくいくかどうかを教えてください。 –