Java Android Studio - 使用 Junit 4.12 “!!! 预计 JUnit 3.8 版或更高版本:”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30629314/
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
Android Studio - with Junit 4.12 “!!! JUnit version 3.8 or later expected:”
提问by Tukajo
Tried out the suggestions on thispost, but I still get the error:
尝试了这篇文章的建议,但我仍然收到错误:
!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
Process finished with exit code -3
Not sure what to do from here. Tried reorganizing the order of the Junit dependency. No luck, anyone else get this issue?
不知道从这里做什么。尝试重新组织 Junit 依赖项的顺序。不走运,还有其他人遇到这个问题吗?
Android Studio V. 1.2.1.1
Android Studio V. 1.2.1.1
采纳答案by Tukajo
Solved the issue. I was running the JUnit tests as a standard "JUnit test" in Android Studio
. I fixed the issue by resetting the configuration as a Android Test
.
解决了这个问题。我在Android Studio
. 我通过将配置重置为Android Test
.
回答by user3278144
I solve this problem by moving "testCompile 'junit:junit:4.12'" to the first order in build.gradle dependency block
我通过将 "testCompile 'junit:junit:4.12'" 移动到 build.gradle 依赖块中的第一个顺序来解决这个问题
回答by ralfoide
Running into this when opening an old project into latest Android Studio 2.3 after it auto-updated the project.
在自动更新项目后将旧项目打开到最新的 Android Studio 2.3 时遇到此问题。
Android Studio supports "Android JUnit" tests which should run using the current host JRE and properly support JUnit 4+. The error is due to the wrong JRE being used.
Android Studio 支持“Android JUnit”测试,该测试应使用当前主机 JRE 运行并正确支持 JUnit 4+。该错误是由于使用了错误的 JRE。
Solved by using Edit Configuration > select the Android JUnit configuration > edit the JRE. Select any choice, use Apply, then change it back to "Default (Android Platform)" for it work.
通过使用编辑配置> 选择Android JUnit 配置> 编辑JRE 解决。选择任何选项,使用应用,然后将其更改回“默认(Android 平台)”以使其正常工作。
回答by WindRider
In my case I just forgot that I've changed the build variant to "release". Switching back to "debug" fixed everything. FML.
就我而言,我只是忘记了我已将构建变体更改为“发布”。切换回“调试”修复了一切。FML。
回答by Naveen Singh
I was also getting similar error when I added new project to workspace. May be they(new Project) would have upgraded Junit version or manadated that project should always use specific version.
当我将新项目添加到工作区时,我也遇到了类似的错误。可能他们(新项目)会升级 Junit 版本或强制该项目应始终使用特定版本。
In this cases, I closed project(all) along with original workspace and opened in new one.
在这种情况下,我关闭了项目(全部)以及原始工作区并在新工作区中打开。
回答by Waqar UlHaq
I've managed to solve it with simply editing the project's app.iml and moving order entry after from bottom:
我设法通过简单地编辑项目的 app.iml 并从底部移动订单条目来解决它:
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
回答by Swati Singh
The below fix is a work around and a repetitive task you need to perform on every new class that you create. I have used Gradle for my project on Android Studio.
以下修复是您需要在您创建的每个新类上执行的变通方法和重复性任务。我在 Android Studio 上的项目中使用了 Gradle。
Step 1: Go to Run-> Edit Configurations Option
步骤 1:转到运行-> 编辑配置 选项
Step 2: For each JUnit test configuration, change and add the below into the fields: a) JRE: Default is selected. Change it to the JRE version you have on your PC which you get as an option in the drop-down. As of today, its 1.8 b) Before launch field: Click on '+', select your module and add task as "clean compileTestJava". Move it to top in the list JUnit test configuration
步骤 2:对于每个 JUnit 测试配置,更改以下内容并将其添加到字段中: a) JRE:选择默认值。将其更改为您在 PC 上拥有的 JRE 版本,您可以在下拉菜单中选择该版本。截至今天,它的 1.8 b) 启动前字段:单击“+”,选择您的模块并将任务添加为“clean compileTestJava”。将其移至JUnit 测试配置列表的顶部
Step 3: Apply Changes and now run your java class.
第 3 步:应用更改,现在运行您的 Java 类。
回答by lubosz
Running an "Android JUNit" config and having JUnit 4.12 in gradle did not help to resolve this.
运行“Android JUNit”配置并在 gradle 中使用 JUnit 4.12 无助于解决此问题。
I needed to select JRE
to Android API 27 Platform
in the run config manually instead of "Default" to resolve the issue.
我需要在运行配置中手动选择JRE
toAndroid API 27 Platform
而不是“默认”来解决问题。
回答by prijupaul
To solve this issue, I set "JRE" to "1.8". This is Under "Edit Configurations"
为了解决这个问题,我将“JRE”设置为“1.8”。这是在“编辑配置”下