I am testing a DAO and in order to do so, I need to extend it with a getAll() method not existing in the production code.
The only way I could think about to achieve this, is to extend my database implementation with an extended DAO containing the getAll() I need. The code looks like the following:
@Database(
entities = [
OneEntity::class,
AnotherEntity::class
],
version = 1,
exportSchema = false
)
abstract class TestDatabase : RoomDatabase() {
abstract fun getOneEntityDao(): OneEntityDao
abstract fun getAnotherEntityDao(): TestAnotherEntityDao
}
@Dao
abstract class TestAnotherEntityDao : AnotherEntityDao {
@Query("""select * from $ANOTHER_ENTITY_TABLE""")
abstract fun getAll() : Single<List<AnotherEntity>>
}
But when I run the tests I get the following error:
`java.lang.RuntimeException: cannot find implementation for com.example.persistence.TestDatabase. TestDatabase_Impl does not exist`
I already checked other answers and the only thing that worked for me is to move the Testdatabase class out of the test directory but I'd rather prefer not to have a test class in my production code.
Any ideas why is this happening and how to solve it?