!!! JUnit version 3.8 or later expected [duplicate

2019-01-23 23:25发布

问题:

This question already has an answer here:

  • IntelliJ IDEA with Junit 4.7 “!!! JUnit version 3.8 or later expected:” 16 answers

My Android studio project has an app module which is android framework dependent, I have created a new module called domain and it contains only pure java classes and a few test classes.

In this module's build.gradle file, I have added junit and mockito libraries for testing purpose as follows:

apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
    testCompile 'junit:junit:4.11'
    testCompile 'org.mockito:mockito-core:1.9.5'
    compile project(':common')
    compile project(':model')
    //test dependencies
}

But Android Studio is giving me !!! JUnit version 3.8 or later expected error message whenever I try to execute the test class.

All the suggested solutions to this problem is to 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.

In fact, I have tried to implement this solution but the problem still exists.

Any idea on how to resolve this issue?

回答1:

I've already solved this just now. It may help you... maybe. A little instruction:

  1. Go to Run -> Edit Configurations
  2. Delete JUnit configuration on left panel



回答2:

I've managed to solve it with simply editing the project's iml and moving order enrty for junit , in my case:

<orderEntry type="library" exported="" scope="TEST" name="junit-4.13-SNAPSHOT" level="project" />

up to be the first orderEntry after </content>



回答3:

I had this but the reason was different..I had inadvertently set my build variant to Release and didn't have any signing info specified so nothing could be built and run on the device.

The cryptic error it gave me was this same one when I tried running the integration tests...didn't notice the app was also disabled :-P Set it back to Debug and it worked fine.



回答4:

I managed to solve the problem by by changing the following in .iml file

from:

 <component name="NewModuleRootManager" inherit-compiler-output="true">

to:

  <orderEntry type="inheritedJdk" />