The answer to this question is not "Android unit tests cannot access Android stack modules such as the Room database because on your desktop they are all stubbed out."
I had a bunch of unit tests that tested static methods that happened to be inside a Dao class - call it FooDao
. They all passed for a year until today, when they stopped passing when the Android Studio editor calls them. They still pass when the command line tests call them, but the editor reports:
java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery
This happens when the unit test gets to FooDao.innocentStaticMethod()
. Like I said, accessing the FooDao
class without invoking any of its real Room methods formerly worked in unit tests.
The long-term fix is to refactor my code so FooDao
only contains real Room calls. But why did Android Studio's test runner suddenly stop working? The version is Android Studio 4.2 RC 1, built on March 23, 2021. And targetSdkVersion 30
.
Switching from
androidx.room:room-runtime:2.2.6
and compiler to2.3.0
did it, on April 22th.In app/build.gradle:
So while I leave a band-aid on the problem until the next time we need to upgrade my mighty
FooDao
, could someone ping Android central about this? ktx