Java !!!预计 JUnit 3.8 或更高版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29172698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:29:54  来源:igfitidea点击:

!!! JUnit version 3.8 or later expected

javaandroidjunit

提问by Fshamri

My Android studio project has an app module which is android framework dependent, I have created a new module called domain and it contains only pure java classes and a few test classes.

我的 Android Studio 项目有一个依赖于 android 框架的应用程序模块,我创建了一个名为 domain 的新模块,它只包含纯 Java 类和一些测试类。

In this module's build.gradle file, I have added junit and mockito libraries for testing purpose as follows:

在这个模块的 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
}

But Android Studio is giving me !!! JUnit version 3.8 or later expectederror message whenever I try to execute the test class.

但是!!! JUnit version 3.8 or later expected每当我尝试执行测试类时,Android Studio 都会给我错误消息。

All the suggested solutions to this problem is to open the Project Structure | Modules | Dependencies, and move the junit-4.7.jar up, so that it comes before Android 1.6 Platform in the classpath.

此问题的所有建议解决方案是打开项目结构 | 模块 | 依赖项,并将 junit-4.7.jar 上移,使其在类路径中位于 Android 1.6 Platform 之前。

In fact, I have tried to implement this solution but the problem still exists. Image of my dependencies structure

事实上,我已经尝试实现这个解决方案,但问题仍然存在。 我的依赖结构的图像

Any idea on how to resolve this issue?

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

采纳答案by Fshamri

I managed to solve the problem by by changing the following in .iml file

我通过更改 .iml 文件中的以下内容设法解决了这个问题

from:

从:

 <component name="NewModuleRootManager" inherit-compiler-output="true">

to:

到:

  <orderEntry type="inheritedJdk" />

回答by Rotem Slootzky

I've managed to solve it with simply editing the project's iml and moving order enrty for junit , in my case:

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

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

up to be the first orderEntry after </content>

最多成为第一个订单Entry之后 </content>

回答by voronnenok

I've already solved this just now. It may help you... maybe. A little instruction:

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

  1. Go to Run -> Edit Configurations
  2. Delete JUnit configuration on left panel
  1. 转到运行-> 编辑配置
  2. 删除左侧面板上的 JUnit 配置

enter image description here

在此处输入图片说明

回答by kenyee

I had this but the reason was different..I had inadvertently set my build variant to Release and didn't have any signing info specified so nothing could be built and run on the device.

我有这个,但原因不同......我无意中将我的构建变体设置为 Release 并且没有指定任何签名信息,因此无法在设备上构建和运行任何内容。

The cryptic error it gave me was this same one when I tried running the integration tests...didn't notice the app was also disabled :-P Set it back to Debug and it worked fine.

当我尝试运行集成测试时,它给我的神秘错误也是同样的错误......没有注意到该应用程序也被禁用了:-P 将其重新设置为 Debug 并且它工作正常。