13

1) 테스트중인 모든 기기/에뮬레이터에서 애니메이션이 사용 중지되었습니다.비정상적인 Android 에스프레소 테스트 - Snackbar

2) 내 Credentials 객체를 작성하는 @BeforeClass가 있습니다.

3) @Before에 등록 된 IntenServiceIdlingResource 및 EventBusIdlingResource가 있습니다.

4) 로그인 버튼을 클릭하면 IntentService가 실행되지 않습니다. 이 경우 서버 (조롱 된 서버)가 500 오류를 반환합니다. 이 정보는 GreenBot의 EventBus를 통해 IntentService에서 UI로 다시 게시되며 Snackbar는 오류 메시지와 함께 표시됩니다. 내 공회전 자원이 작업 내 기록에 따르면

SignInExceptionTest > a_userNamePasswordTest[Nexus_6P_API_23(AVD) - 6.0] FAILED android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: a string starting with "Server Error: 500"

:

@Test 
public void a_userNamePasswordTest() throws Exception { 
    // email input 
    ViewInteraction userNameView = onView(withId(R.id.email)); 

    // verify it's on screen and enabled 
    userNameView.check(matches(isDisplayed())).check(matches(isEnabled())); 

    // set the username 
    userNameView.perform(scrollTo(), replaceText(credentials.username), closeSoftKeyboard()); 

    // password input 
    ViewInteraction passwordView = onView(withId(R.id.password)); 

    // verify it's on screen and enabled 
    passwordView.check(matches(isDisplayed())).check(matches(isEnabled())); 

    // set the password. 
    passwordView.perform(scrollTo(), replaceText(credentials.password), closeSoftKeyboard()); 

    // sign in button 
    ViewInteraction signInButton = onView(withId(R.id.email_sign_in_button)); 

    // verify the button 
    signInButton.check(matches(allOf(
      isDisplayed(), isEnabled(), withText("Sign In"), withContentDescription("Sign In") 
    ))); 

    // clickity click the button 
    signInButton.perform(scrollTo(), click()); 

    // verify the snackbar text 
    onView(withText(startsWith("Server Error: 500"))).check(matches(isDisplayed())); 

} 

이 내가 일반적으로 얻을 예외는 :

다음은 테스트를위한 코드입니다. 그러나 로그의 타임 스탬프를 보면 유휴 리소스가 유휴 상태로 된 후 약 5 초가 지나면 예외가 발생합니다.

리소스가 유휴 상태가 될 때와보기를 찾을 때 사이에 지연이있는 것처럼 보입니다.

다른 가능성 관련 세부 정보 :

  • minSdk : 25
  • buildTools : 25.0.2
  • 지원 라이브러리 : 25.1.1
  • 에스프레소 코어 (20)
  • & targetSdk 컴파일 : 2.2.2
  • gradle plugin 2.3.0-beta3

스낵바가 표시되는 시간을 팽창시키는 것 외에이 테스트가 불규칙하지 않도록 수정하려면 어떻게해야합니까?

답변

12

Espresso는 IdlingResource가 활성 상태가 된 후 다시 유휴 상태인지 점검하기 전에 5 초 대기를 적용합니다.

내 경우에는 2 가지 부정적인 영향을 미칩니다.

먼저 테스트가 실행되는 데 걸리는 시간이 길어집니다. 모든 테스트에서 5 초 (또는 5의 배수)가 실제로 추가 될 수 있습니다.

두 번째로, 스낵 바가 즉시 표시되고 약 3.5 초 동안 보여주기 때문에, IdlingResource를 기다리는 동안 언제나 스낵바는 사라질 것입니다. Espresso는 리소스가 유휴 상태임을 깨닫고 테스트 할.

ConditionWatcher는 여기에 설명 : https://medium.com/azimolabs/wait-for-it-idlingresource-and-conditionwatcher-602055f32356#.9rms52osh

그리고 코드 여기 : https://github.com/AzimoLabs/ConditionWatcher

해결책이 두 가지 문제를 제공합니다. 5 초가 아니라 250ms로 기본 설정되며이 값은 조정할 수 있습니다 (setWatchInterval).

+0

감사합니다. IdlingResource에 대한 에스프레소의 의존은 나를 바나나로 몰고갔습니다. 클래스에 테스트 프레임 워크 코드를 뿌려야 할 이유가 없습니다. 이것이 올바르게 수행되어야하는 방법입니다. 나는 아직도 에스프레소가 이것 같이 무언가를 이미다는 것을 믿을 수 없다! –

관련 문제