3

If I try to run my unit tests in Android Studio, I always get this error:

!!! JUnit version 3.8 or later expected:

java.lang.ClassNotFoundException: junit.framework.ComparisonFailure
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:221)
    at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:207)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:61)

My gradle dependencies look like this:

def google_services = "15.0.1"

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // for tests
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'org.powermock:powermock-api-mockito2:1.7.4'
    androidTestImplementation 'org.powermock:powermock-module-junit4:1.7.4'

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:gridlayout-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'

    implementation 'com.android.support.constraint:constraint-layout:1.1.2'

    implementation "com.google.android.gms:play-services-maps:${google_services}"
    implementation "com.google.android.gms:play-services-location:${google_services}"
    implementation "com.google.android.gms:play-services-gcm:${google_services}"
    implementation "com.google.android.gms:play-services-analytics:16.0.1"
    implementation "com.google.firebase:firebase-messaging:17.1.0"
    implementation 'com.google.firebase:firebase-core:16.0.1'

    implementation 'com.google.android.exoplayer:exoplayer:2.6.1'

    implementation 'com.github.bumptech.glide:glide:4.7.1'

    implementation 'com.androidmapsextensions:android-maps-extensions:2.2.0'

    implementation 'com.squareup:otto:1.3.8'
    implementation 'com.squareup.retrofit:retrofit:1.9.0'
    implementation 'com.squareup.picasso:picasso:2.71828'

    implementation 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
    implementation 'com.github.rtoshiro.securesharedpreferences:securesharedpreferences:1.2.0'

    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    implementation('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        transitive = true
    }
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.zcw:togglebutton-library:1.0.0'
    implementation 'com.android.support:exifinterface:27.1.1'
}

My Tests looks like this:

@RunWith(MockitoJUnitRunner.class)
public class MyTest {

    @Test
    public void testTestIt() {
        // some test code
    }
}

I tried all the following "solutions", but none of them worked:

Can someone maybe point me into the right direction?

Some more info:

  • compileSdkVersion 27
  • Only one module in the project
  • Android Studio 3.1.4 on Mac OSX
  • JRE 1.8.0_152
L.Butz
  • 2,466
  • 25
  • 44
  • Did you try to change the order of dependencies inside the pom file so that Android SDK comes after JUnit? – 0xAliHn Aug 13 '18 at 10:55
  • @0xalihn I'm not exactly sure what you mean, but I also tried to have the junit:4.12 as the very first dependency in my gradle.build file, but that also didn't work. – L.Butz Aug 13 '18 at 11:13
  • yup, in the same boat with Android Studio 3.4.2, also tried all suggestions written in the links, none of them worked – ykonda Aug 05 '19 at 19:33

0 Answers0