【发布时间】:2015-03-20 17:42:39
【问题描述】:
我的 Android Studio 项目有一个依赖于 android 框架的 app 模块,我创建了一个名为 domain 的新模块,它只包含纯 java 类和一些测试类。
在这个模块的 build.gradle 文件中,我添加了 junit 和 mockito 库用于测试目的如下:
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
}
但每当我尝试执行测试类时,Android Studio 都会给我!!! JUnit version 3.8 or later expected 错误消息。
此问题的所有建议解决方案是打开项目结构 |模块 |依赖关系,并将 junit-4.7.jar 向上移动,使其在类路径中位于 Android 1.6 Platform 之前。
其实我已经尝试过实现这个解决方案,但是问题依然存在。
知道如何解决这个问题吗?
【问题讨论】:
-
您的运行/调试配置对于您的测试来说是什么样的?具体来说,“使用模块的类路径”属性对您的测试有何意义?您可以在 Run -> Edit Configurations 上找到它,然后在左侧选择一个配置。
-
发布您的
build.gradle。 -
我可以通过删除
unitTest.returnDefaultValues来解决它,检查:stackoverflow.com/a/44820309/965569