android / android/testing-samples

Robolectric 4 support

Offen
#237 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
9.3k
Forks
3.6k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

As I have read, tests written with androidx.test.* are supposed to be executed either as an instrumented test (in a real device or emulator) or in the JVM with robolectric 4. So I have copied the ChangeTextBehaviorKtTest in the test folder, and I have added robolectric 4 dependency to gradle file. Also I have copied the rest of androidx.test.* dependencies with testImplementation keyword. Everything seems ok, until I try to execute the tests.

This is what I get:

[Robolectric] com.example.android.testing.espresso.BasicSample.ChangeTextBehaviorKtTest2.changeText_sameActivity: sdk=28; resources=binary
Called loadFromPath(/system/framework/framework-res.apk, true); mode=binary sdk=28

androidx.test.espresso.PerformException: Error performing 'close keyboard' on view 'with id: com.example.android.testing.espresso.BasicSample:id/editTextUserInput'.

Caused by: java.lang.RuntimeException: Attempt to close the soft keyboard did not result in soft keyboard to be hidden. resultCode = -1

So I have removed the call to closeSoftKeyboard() function, as I have noticed that is not necessary with instrumented tests so that they can be executed successfully.

When I remove the call to that funcion, the first test changeText_sameActivity is executed successfully, but the second still fails, with this new exception:

[Robolectric] com.example.android.testing.espresso.BasicSample.ChangeTextBehaviorKtTest2.changeText_newActivity: sdk=28; resources=binary
Called loadFromPath(/system/framework/framework-res.apk, true); mode=binary sdk=28

androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.example.android.testing.espresso.BasicSample:id/show_text_view

View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=320, height=470, 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=APPLICATION wanim=0x10302f8
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=1}

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit dem kopierten ChangeTextBehaviorKtTest und den in der Issue beschriebenen Gradle-Testabhängigkeiten und führe dann sowohl changeText_sameActivity als auch changeText_newActivity unter Robolectric 4 aus. Vergleiche den Keyboard-Fehler und die fehlende show_text_view-Hierarchie mit dem instrumentierten Verhalten; fertig ist die Aufgabe, wenn beide Tests erfolgreich ausgeführt werden, ohne die Keyboard-Aktion zu entfernen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
testing
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.