I am working on an Android project (in Android Studio), with a small amount of SDK, which is pure java.
So, I want to do a test with JUnit4.
And I configured the Gradlle file like this:
apply plugin: 'android' android { compileSdkVersion "Google Inc.:Google APIs:19" buildToolsVersion "19.0.1" lintOptions{ checkReleaseBuilds false } defaultConfig { minSdkVersion 8 targetSdkVersion 19 versionCode 28 versionName "4.0.5" } signingConfigs { debug { } release { } } buildTypes { debug{ runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' debuggable true buildConfigField "boolean", "LOG_ENABLED", "true" signingConfig signingConfigs.debug } release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' debuggable false buildConfigField "boolean", "LOG_ENABLED", "false" signingConfig signingConfigs.release } } productFlavors{ develFlavor{ } testFlavor{ } trainingFlavor{ } preFlavor{ } proFlavor{ } } } if (project.hasProperty('storePassword')) { android.signingConfigs.release.storePassword = storePassword } if (project.hasProperty('keyAlias')) { android.signingConfigs.release.keyAlias = keyAlias } if (project.hasProperty('keyPassword')) { android.signingConfigs.release.keyPassword = keyPassword } //testing sourceSets { unitTest { java.srcDir file('test') resources.srcDir file('test/resources') } } configurations { unitTestCompile.extendsFrom runtime unitTestRuntime.extendsFrom unitTestCompile } task unitTest(type:Test, dependsOn: assemble) { description = "run unit tests" testClassesDir = project.sourceSets.unitTest.output.classesDir classpath = project.sourceSets.unitTest.runtimeClasspath } build.dependsOn unitTest dependencies { compile files('libs/junit-4.11-sources.jar') unitTestCompile 'junit:junit:4.11' unitTestCompile files("$project.buildDir/classes/debug") compile 'com.google.code.gson:gson:+' compile 'com.android.support:appcompat-v7:+' compile files('libs/libGoogleAnalyticsServices.jar') compile files('libs/sbc_mapslib.jar') compile files('libs/t21c2dm-lib-v1.0.jar') }
Then I do a simple test case to see if junitis works. But when I run it, this error will be skipped.
!!! JUnit version 3.8 or later expected:
I saw in another question what the solutions were, change the dependencies of Junit4.jar to the first position, but this does not work for
source share