IntelliJ IDEA with Junit 4.7 "!!! JUnit version 3.8 or later expected:"
my module is a java library module, so changing JRE to 1.8 java solved the issue.
Or, you can also do it globally via Module Settings > SDK Location > JDK, specifying Oracle's JDK 8 instead of Android SDK's copy.
I had this problem with a multi module project (libgdx). One module is pure Java and has tests. My solution was to set "use alternative JRE" to "Java 1.8" in the run configuration of my unit tests. This makes sure no android.jar is on the classpath and the junit 4.x runner is used.
I got the same error when creating both Unit Test
and Android Instrument Test
in Android Studio 1.4+ and it started to get confused. To avoid this error make sure your test class is fall under Android Tests
on Run/Debug Configurations
- Make sure you follow the instruction properly https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
- Make sure
Test Artifact
inBuild Variants
is set toAndroid Instrumentation Tests
- Click menu
Run
>Edit Configuration
- Make sure your class/method name is inside
Android Tests
instead ofJUnit
- If it is in
JUnit
simply delete the config and right click on the file you want to test andRun
again. It will then create the config underAndroid Tests
section and it run on device/emulator.
This problem happens because Android Platform (android.jar
) already contains JUnit classes. IDEA test runner loads these classes and sees that they are from the old JUnit, while you are trying to use annotated tests which is a feature of the new JUnit, therefore you get the error from the test runner.
The solution is simple, open the Project Structure
| Modules
| Dependencies
, and move the junit-4.7.jar
up, so that it comes before Android 1.6 Platform
in the classpath. Now the test runner will be happy as it loads the new JUnit version.