I'm currently trying to run an instrumented test of Realm with a listener. I'm pretty new to Android and have read the minimal Realm documentation and SO questions but really can't figure this out.
I have this realm test class that I subclass for future use
open class RealmInstrumentedUnitTest {
lateinit var mockRealm: Realm
@Before
fun setup() {
Looper.prepare()
val testConfig = RealmConfiguration.Builder().inMemory().name("test-realm").build()
Realm.setDefaultConfiguration(testConfig)
this.mockRealm = Realm.getDefaultInstance()
}
@After
@Throws(Exception::class)
public fun tearDown() {
Looper.loop()
this.mockRealm.close()
}
}
Then I subclass the preceding and implement a test:
@Test
fun testOverlappingSessionDeletion() {
val realm = this.mockRealm
this.sessions = realm.where(Session::class.java).findAll() // monitor session deletions
this.sessions?.addChangeListener { t, changeSet ->
val deletedSessions = realm.where(Session::class.java).`in`("id", changeSet.deletions.toTypedArray()).findAll()
deletedSessions.forEach { it.cleanup() }
}
- I can't figure how to configure the looper to make it run
- In this configuration I get "Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed.'."
- If I put the
Looper.loop()
earlier I get a never ending loop
How should I configure this to run it properly?
Thank you so much
Aucun commentaire:
Enregistrer un commentaire