При выполнении тестов Kotlin Unit и UI, 1 или 2 новых теста все время терпят неудачу - PullRequest
0 голосов
/ 08 октября 2019

Я пытаюсь запустить тестирование юнитов и пользовательского интерфейса в Котлине с использованием Junit и Espresso. Что действительно интересно, так это то, что каждый раз, когда я запускаю весь тест, 1 или 2 новых теста терпят неудачу. Кажется, в моих тестовых настройках есть систематический сбой. Что будет причиной этой проблемы? Любые предложения, где я должен начать отладку?

Настройка теста:

// Build.gradle
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.recyclerview:recyclerview:1.0.0"
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
    implementation 'androidx.room:room-runtime:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
    kapt 'androidx.room:room-compiler:2.1.0'

    // test implementation
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.powermock:powermock-module-junit4:1.7.4'
    testImplementation 'org.powermock:powermock-api-mockito2:1.7.4'

    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'

    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:retrofit:2.6.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
}

Несколько типов сообщений об ошибках, с которыми я сталкиваюсь в этой проблеме:

type 1:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: xyz.hitit.userapplication.debug, PID: 11286
    java.lang.IllegalStateException: pwdEditText must not be null
        at xyz.hitit.userapplication.ui.registrationLogin.PasswordLoginFragment$onCreateView$1$1$1.run(PasswordLoginFragment.kt:72)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/MonitoringInstr: Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords.
    java.lang.IllegalStateException: pwdEditText must not be null
        at xyz.hitit.userapplication.ui.registrationLogin.PasswordLoginFragment$onCreateView$1$1$1.run(PasswordLoginFragment.kt:72)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

тип 2:

androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (Child at position 1 in parent (with id: xyz.hitit.userapplication.debug:id/design_navigation_view and Child at position 0 in parent with id: xyz.hitit.userapplication.debug:id/nav_view) and is displayed on the screen to the user)

View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=2160, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params={(0,0)(fillxfill) ty=BASE_APPLICATION wanim=0x10302fe
fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
pfl=FORCE_DRAW_STATUS_BAR_BACKGROUND}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=2028, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@cf89f9f, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
(133 more lines...)

тип 3:

androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "randomTextToShowXButton"' doesn't match the selected view.
Expected: with text: is "randomTextToShowXButton"
Got: "ClearEditText{id=2131230812, res-name=emailEditText, visibility=VISIBLE, width=938, height=132, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@bbfd43f, tag=null, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x21 imeOptions=0x6 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=19 initialSelEnd=19 initialCapsMode=0x0 hintText=youremail@email.com label=null packageName=null fieldId=0 fieldName=null extras=null hintLocales=null contentMimeTypes=null ], x=71.0, y=572.0, text=randomTextToShowXBu, hint=youremail@email.com, input-type=33, ime-target=true, has-links=false}"

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1720)
at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:96)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:59)
(51 more lines...)

тип 4:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at androidx.fragment.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2080)
at androidx.fragment.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2106)
at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:683)
at androidx.fragment.app.BackStackRecord.commit(BackStackRecord.java:637)
at xyz.hitit.userapplication.ui.registrationLogin.RegisterLoginActivity$onCreate$1.invoke(RegisterLoginActivity.kt:42)
at xyz.hitit.userapplication.ui.registrationLogin.RegisterLoginActivity$onCreate$1.invoke(RegisterLoginActivity.kt:14)
at xyz.hitit.api.methods.OAuth$requestJWTClientCredentials$1.onResponse(OAuth.kt:37)
(8 more lines...)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...