android studio 4.12,Android Studio - with Junit 4.12 “!!! JUnit version 3.8 or later expected:”

本文档汇总了Android Studio中遇到的JUnit4测试错误的解决方案,包括检查依赖项顺序、设置正确的JRE版本、配置AndroidTest以及解决Gradle版本不匹配等问题。通过这些步骤,可以成功运行JUnit4测试。
摘要由CSDN通过智能技术生成

Tried out the suggestions on this post, but I still get the error:

!!! JUnit version 3.8 or later expected:

java.lang.RuntimeException: Stub!

at junit.runner.BaseTestRunner.(BaseTestRunner.java:5)

at junit.textui.TestRunner.(TestRunner.java:54)

at junit.textui.TestRunner.(TestRunner.java:48)

at junit.textui.TestRunner.(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?

Android Studio V. 1.2.1.1

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.

I solve this problem by moving "testCompile 'junit:junit:4.12'" to the first order in build.gradle dependency block

Running into this when opening an old project into latest Android Studio 2.3 after it auto-updated the project.

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.

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.

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.

Step 1:

Go to Run-> Edit Configurations

Option

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

Step 3: Apply Changes and now run your java class.

I was having the same error and I fixed it by updating JRE value under "Edit Configurations..." in Android Studio, I used API 28 instead and then it worked. Please check the image for your reference...

a9f128ca421c58d9e59d53770816ac6c.png

In my case I just forgot that I've changed the build variant to "release". Switching back to "debug" fixed everything. FML.

Running an "Android JUNit" config and having JUnit 4.12 in gradle did not help to resolve this.

I needed to select JRE to Android API 27 Platform in the run config manually instead of "Default" to resolve the issue.

To solve this issue, I set "JRE" to "1.8". This is Under "Edit Configurations"

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.

In this cases, I closed project(all) along with original workspace and opened in new one.

I've managed to solve it with simply editing the project's app.iml and moving order entry after from bottom:

来源:https://stackoverflow.com/questions/30629314/android-studio-with-junit-4-12-junit-version-3-8-or-later-expected

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值