"레코드 에스 프레소 테스트 기능"을 사용하여 Android 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'
내가 테스트 케이스 자바 파일 (1000)에 Thread.sleep를 사용하여 시도는, 컨트롤이 처음 몇 점검을 위해 잘 실행하지만, 다시 충돌 그 후에 뷰 동작이 수행 될 때. 내 케이스의 NoMatchingViewException을 해결할 방법이 있습니까? 이 이벤트를 처리 할 수 있도록
는public static void waitAsync(long milliseconds) {
try {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
return null;
}
}.get(milliseconds, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
는 주 스레드를 정지하지 않지만, 코드는 제한 시간을 기다리고 있습니다 :
감사합니다, 나는 것 접근 방식을 시도하고 그것이 효과적인지 아닌지 알려주십시오. –