How can be done a simple test of a realm database in Android implementing the test in Kotlin?
I attempted to adapt a fragment from java realm test on github to kotlin and got the next code:
import io.realm.Realm
import io.realm.log.RealmLog
import org.hamcrest.CoreMatchers
import org.junit.Assert
import org.junit.Test import org.junit.Before import org.junit.Rule
import org.mockito.Mockito.`when`
import org.powermock.api.mockito.PowerMockito
import org.powermock.modules.junit4.rule.PowerMockRule
class DBTest {
@Rule
var rule = PowerMockRule()
lateinit internal var mockRealm: Realm
@Before
fun setup() {
PowerMockito.mockStatic(RealmLog::class.java)
PowerMockito.mockStatic(Realm::class.java)
val mockRealm = PowerMockito.mock(Realm::class.java)
`when`(Realm.getDefaultInstance()).thenReturn(mockRealm)
this.mockRealm = mockRealm
}
@Test
fun shouldBeAbleToGetDefaultInstance() {
Assert.assertThat(Realm.getDefaultInstance(), CoreMatchers.`is`(mockRealm))
}
}
But when I execute the test I get:
org.junit.internal.runners.rules.ValidationError: The @Rule 'rule' must be public.
Aucun commentaire:
Enregistrer un commentaire