Room Testing in Android
Best Practice
- while writing unit tests for a class follow the same package structure. eg - data -> local -> className then in androidTest data -> local -> classNameTest
Annotations
-_@RunWith(AndroidJUnit4::class) - These tests don't run in core java or kotlin environment. To run these tests as instrument tests on the emulator we write this annotation.
-@SmallTest - It is used to refer to unit test. If it was an integrated test we would have written @MediumTest. For UI it would be _@LargeTest
Methods
- Room.inMemoryDatabaseBuilder() - It will create a fake database. The database will be there but it will be in ram. We cannot create a database for every test case. It will not be persistent. Normally we use Room.databaseBuilder() to create a database.