android / android/android-test
android.os.BadParcelableException: ClassNotFoundException when unmarshalling
- Lingua principale
- Java
- Stelle
- 1.2k
- Fork
- 342
- Merge medio
- 11h 29m
- PR unite (30g)
- 2
Descrizione
### Description
Asserting on activity result extra from `ActivityScenario` results in exception. This was not the case with `ActivityTestRule`.
### Steps to Reproduce
2. Start "picker" activity with `scenario = ActivityScenario.launch(intent)`
3. Simulate result_ok with included parcelable extra
4. Assert on activity result intent extras (which triggers unmarshalling ClassNotFoundException exception) with
```
val activityResult = scenario.result!!
assertThat(activityResult, hasResultCode(RESULT_OK))
assertThat(activityResult, hasResultData(hasExtraWithKey(KEY_SELECTED_CITY)))
```
### Expected Results
Assertion works
### Actual Results
Exception similar to next one:
```
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: my.package.ParcelableAutoCompleteCity
at android.os.Parcel.readParcelableCreator(Parcel.java:3042)
at android.os.Parcel.readParcelable(Parcel.java:2964)
at android.os.Parcel.readValue(Parcel.java:2866)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3244)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292)
at android.os.BaseBundle.unparcel(BaseBundle.java:236)
at android.os.BaseBundle.keySet(BaseBundle.java:562)
at androidx.test.espresso.intent.matcher.BundleMatchers$BundleMatcher.matchesSafely(BundleMatchers.java:47)
at androidx.test.espresso.intent.matcher.BundleMatchers$BundleMatcher.matchesSafely(BundleMatchers.java:35)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:67)
at androidx.test.espresso.intent.matcher.IntentMatchers$7.matchesSafely(IntentMatchers.java:215)
at androidx.test.espresso.intent.matcher.IntentMatchers$7.matchesSafely(IntentMatchers.java:206)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:67)
at androidx.test.espresso.contrib.ActivityResultMatchers$1.matchesSafely(ActivityResultMatchers.java:46)
at androidx.test.espresso.contrib.ActivityResultMatchers$1.matchesSafely(ActivityResultMatchers.java:37)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:67)
at androidx.test.espresso.matcher.ViewMatchers.assertThat(ViewMatchers.java:7)
at androidx.test.espresso.matcher.ViewMatchers.assertThat(ViewMatchers.java:5)
```
### AndroidX Test and Android OS Versions
1.3.0 and sdk29
### Link to a public git repo demonstrating the problem:
I need some guidance. I guess this repo should have already some tests which work on activity result verification. What are they? I would then extend them to include parcelable extra into activity result intent.
### Current workaround
Set classloader explicitly before asserting result
```
val activityResult = scenario.result!!
activityResult.resultData.setExtrasClassLoader(this::class.java.classLoader)
assertThat(activityResult, hasResultCode(RESULT_OK))
assertThat(activityResult, hasResultData(hasExtraWithKey(KEY_SELECTED_CITY)))
```
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con i percorsi ActivityScenario.result, ActivityResultMatchers e BundleMatchers mostrati nello stack trace. Riproduci l’asserzione sugli extra parcelable su SDK 29, poi esamina i test esistenti di verifica dei risultati delle activity ed estendine uno per coprire l’unmarshalling. Il lavoro è completo quando l’asserzione ha esito positivo senza impostare manualmente il class loader degli extra.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java, kotlin
- Ambito
- mobile-dev, testing
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100