Android Studio - with Junit 4.12 “!!! JUnit version 3.8 or later expected:”
Solution 1
Solved the issue. I was running the JUnit tests as a standard "JUnit test" in Android Studio
. I fixed the issue by resetting the configuration as a Android Test
.
Solution 2
Just to add one more situation. I was having this error after updating Android Studio to 4.1 on a project using old AGP (3.3.2) and Gradle (4.10.2). What ended up solving the issue for me was removing the android.test.runner
library from gradle dependencies, that is removing the following line from the app's module build.gradle
:
useLibrary 'android.test.runner'
I probably got lucky to not actually need any of the classes provided by the library for unit or instrumented tests.
Solution 3
If you have updated android studio version to 4.1 wiuth latest gradle plygin. Please comment out
// useLibrary 'android.test.runner' It will fix error for you.
Solution 4
I solve this problem by moving "testCompile 'junit:junit:4.12'" to the first order in build.gradle dependency block
Solution 5
This is apparently an Android Studio 4.1 issue. There's an open ticket for that already: https://issuetracker.google.com/issues/170328018
What really solved the issue for me was reinstalling the Android 11 (API 30) SDK, according to the bug ticket above:
"...there was an issue with API 30 mock jar that was built incorrectly. Can you open Android Studio SDK Manager and try uninstalling the R SDK or any Android SDK Platform 30 please? The Gradle build will auto install it when you try to rebuild after you delete the R SDK."
Comments
-
Timothy Frisch almost 2 years
Tried out the suggestions on this post, but I still get the error:
!!! JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub! at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5) at junit.textui.TestRunner.<init>(TestRunner.java:54) at junit.textui.TestRunner.<init>(TestRunner.java:48) at junit.textui.TestRunner.<init>(TestRunner.java:41) Process finished with exit code -3
Not sure what to do from here. Tried reorganizing the order of the Junit dependency. No luck, anyone else get this issue?
Android Studio V. 1.2.1.1
-
Bulwinkel over 8 yearsThis worked for me but it took a bit to work out how to create an
Android Test
. Go toEdit Configurations
, selectAndroid Tests
from the menu on the left, click+
, and fill in the details on the right. -
ericharlow over 8 yearsif you want to run your test as a standard Junit test be sure your build variant in android studio is set to Unit Tests and then create a Junit test configuration.
-
Julian A. over 5 yearsyou, sir, are a scholar and a gentleman!! thank you - your fixed worked.
-
Alejandro Casanova over 5 yearsI'm glad it did, best regards!
-
Mr-IDE almost 5 yearsThis worked for me, when using Robolectric for unit tests.
-
buggily over 3 yearsThis fixed the issue for me as well. Thank you!
-
Henrique over 3 yearsThat also worked for me after updating to Android Studio 4.1! Thank you so much for posting this! You saved me a few hours of debugging. Cheers
-
Olivier Bonal over 3 yearsFixed it for me for Android Studio 4.1 too! Thanks a lot! :-)
-
beli over 3 yearsFixed it on Android Studio 4.1
-
Chris over 3 yearsThis was the only thing that worked for me - thank you!
-
Admin over 3 yearsAlso had to remove
useLibrary 'android.test.base'
anduseLibrary 'android.test.mock'
- thanks!