我正在做Android项目(在Android Studio中),里面有一个纯Java的小SDK.
所以我想要的是从JUnit4进行测试.
我以这种方式配置了Gradlle文件:
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') }
然后我做一个简单的测试案例,看看junitis是否正常工作.但是当我运行它时,会出现此错误.
!!! JUnit version 3.8 or later expected:
我在其他一些问题中看到解决方案是,将Junit4.jar的依赖性改为第一位,但它不起作用