After updating junit version to 4.13 in gradle dependencies, classes and annotations like Assert
, @Test
, etc. under the junit package are displayed as red when used in my code. Lint check says:
Unresolved reference: <any junit class>
However, when I build and run my tests, it will build and run just fine.
I have tried:
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
What works is downgrading junit to 4.12. How to get rid of this lint error, without downgrading version?
Update:
ALT + ENTER
options and select Inspection 'Unresolved reference, in wrong test scope' options
> Suppress 'IncorrectScope' for file <name of file>
, it gets rid of these lint errors for that particular file. I still like to solve this problem without using Suppress though.If you still see the unresolved reference error after fixing the problem, try to build your Android application with Command + F9 for Mac or Control + F9 for Windows and Linux. The error should disappear after the build is completed.
Just add the following to your build.gradle (App) file:
configurations.all {
resolutionStrategy.force "junit:junit:$junit_version"
}
dependencies {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With