Setup inMemory Realm for Instrumented Tests
See original GitHub issueGoal
Setup inMemory Realm while running Instrumented tests
Actual Results
Realm cannot be initialized from androidTest package
Steps & Code to Reproduce
@Before
fun setup() {
Realm.init(MessengerApplication.context)
val config = RealmConfiguration.Builder()
.name("realm.test")
.inMemory()
.build()
realm = Realm.getInstance(config)
}
java.lang.NoSuchMethodError: No static method init(Landroid/content/Context;)V in class Lio/realm/Realm; or its super classes
Strangely, the code works if I setup realm in my Application class and set the default config to inMemory.
Version of Realm and tooling
Realm version(s): 4.1.1
Realm sync feature enabled: No
Android Studio version: 3.0
Which Android version and device: 7.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Android - Realm - Instrumented Unit Tests - Stack Overflow
everybody. I have a question bounded to Realm. Realm is new technology for me. I need test functionality - correctness of updates, inserts, ......
Read more >Android: Testing Realm - Medium
This article demonstrated an alternative approach to test Realm on Android. It relies on Realm's in-memory feature and Android's connected ...
Read more >Testing - Java SDK — Realm - MongoDB
You can run integration tests by communicating with actual instances of Realm Database or an App backend using Android's built-in instrumented tests.
Read more >Testing Room Database in Android using JUnit - GeeksforGeeks
Create a new class “Language.kt” and annotate it with @Entity and pass the table name. Kotlin. Kotlin ...
Read more >Testing Realm Apps - Realm Academy
Note: the test above is far from being comprehensive, the point we're trying to make is on the setup. Benchmark: on-disk vs in-memory....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Interesting. Thanks for the info 👍
@cmelchior I think I found the problem!
as I was removing all unused methods in the debug build,
inMemory()
was not found when I mentioned in the androidTest package. Moreover, when I moved all the Realm initialization to androidTest, it could not find anything! simply ignoring Realm classes in Proguard settings resolved the issue!