!!!预期的 JUnit 版本 3.8 或更高版本

2022-09-01 18:31:49

我的Android工作室项目有一个依赖于Android框架的应用程序模块,我创建了一个名为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 之前。

实际上,我已经尝试实现此解决方案,但问题仍然存在。Image of my dependencies structure

关于如何解决此问题的任何想法?


答案 1

我刚才已经解决了这个问题。它可能会帮助你...或。一点说明:

  1. 转到运行 ->编辑配置
  2. 删除左侧面板上的 JUnit 配置

enter image description here


答案 2

在我的情况下,我已经设法通过简单地编辑项目的iml和junit的移动顺序enrty来解决它:

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

直到成为第一个订单进入之后</content>


推荐