I am developing and Android app using Android Studio. While trying to run some JUnit tests for my database, I am getting multiple “unresolved reference” errors:
e: C:\Users\Rene\AndroidStudioProjects\count13\app\src\test\java\me\renespies\count13\Count13DatabaseUnitTest.kt: (5, 17): Unresolved reference: test
e: C:\Users\Rene\AndroidStudioProjects\count13\app\src\test\java\me\renespies\count13\Count13DatabaseUnitTest.kt: (6, 17): Unresolved reference: test
e: C:\Users\Rene\AndroidStudioProjects\count13\app\src\test\java\me\renespies\count13\Count13DatabaseUnitTest.kt: (25, 10): Unresolved reference: AndroidJUnit4
e: C:\Users\Rene\AndroidStudioProjects\count13\app\src\test\java\me\renespies\count13\Count13DatabaseUnitTest.kt: (25, 10): An annotation argument must be a compile-time constant
e: C:\Users\Rene\AndroidStudioProjects\count13\app\src\test\java\me\renespies\count13\Count13DatabaseUnitTest.kt: (36, 17): Unresolved reference: ApplicationProvider
All dependencies are added and up to date and I can use all references - imports as well as classes - from above errors without any problems.
The first to errors point to two imports
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
which produce no error before building.
And the other two unresolved references, AndroidJUnit4
and ApplicationProvider
, are classes I use to test my database, which work fine (also auto completion).
The annotation argument
error is a byproduct of the “missing” AndroidJUnit4
reference.
How can this be? If the dependencies were missing, I would not be able to use auto completion, as Android Studio would not know about the classes and their functions, would it? How can I resolve this error and make my tests run?