带有 Junit 4.7 的 IntelliJ IDEA "!!!预计 JUnit 3.8 版或更高版本:" [英] IntelliJ IDEA with Junit 4.7 "!!! JUnit version 3.8 or later expected:"

查看:35
本文介绍了带有 Junit 4.7 的 IntelliJ IDEA "!!!预计 JUnit 3.8 版或更高版本:"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 IntelliJ IDEA 中运行以下测试时,我收到消息:><块引用>

"!!! JUnit 3.8 或更高版本预期:"

需要注意的是,这是我正在开发的 Android 项目在 IntelliJ IDEA 9 中.

公共类 GameScoreUtilTest {@测试public void testCalculateResults() 抛出异常 {最终游戏游戏 = 新游戏();最终玩家 player1 = new Player();{final PlayedHole PlayedHole = new PlayedHole();playHole.setScore(1);game.getHoleScoreMap().put(player1,playedHole);}{final PlayedHole PlayedHole = new PlayedHole();playHole.setScore(3);game.getHoleScoreMap().put(player1,playedHole);}final GameResults gameResults = GameScoreUtil.calculateResults(game);assertEquals(4, gameResults.getScore());}}

完整的堆栈跟踪看起来像这样...

<代码>!!!预计 JUnit 3.8 版或更高版本:java.lang.RuntimeException:存根!在 junit.runner.BaseTestRunner.(BaseTestRunner.java:5)在 junit.textui.TestRunner.(TestRunner.java:54)在 junit.textui.TestRunner.(TestRunner.java:48)在 junit.textui.TestRunner.(TestRunner.java:41)在 com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:152)在 com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:136)在 com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:49)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)在 java.lang.reflect.Method.invoke(Method.java:597)在 com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)进程完成,退出代码 -3

解决方案

出现这个问题是因为 Android 平台 (android.jar) 已经包含 JUnit 类.IDEA 测试运行器加载这些类并发现它们来自旧的 JUnit,而您尝试使用带注释的测试(这是新 JUnit 的一个特性),因此您会从测试运行器中得到错误.

解决方法很简单,打开Project Structure |模块 |Dependencies,并将 junit-4.7.jar 上移,使其之前 Android 1.6 Platform 出现在类路径.现在测试运行器会很高兴加载新的 JUnit 版本.

When I attempt to run the following test in IntelliJ IDEA I get the message:

"!!! JUnit version 3.8 or later expected:"

It should be noted that this is an Android project I am working on in IntelliJ IDEA 9.

public class GameScoreUtilTest {
    @Test
    public void testCalculateResults() throws Exception {
        final Game game = new Game();

        final Player player1 = new Player();
        {
            final PlayedHole playedHole = new PlayedHole();
            playedHole.setScore(1);
            game.getHoleScoreMap().put(player1, playedHole);
        }
        {
            final PlayedHole playedHole = new PlayedHole();
            playedHole.setScore(3);
            game.getHoleScoreMap().put(player1, playedHole);
        }
        final GameResults gameResults = GameScoreUtil.calculateResults(game);

        assertEquals(4, gameResults.getScore());
    }
}

The full stack trace looks like this...

!!! 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)
    at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:152)
    at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:136)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)

Process finished with exit code -3

解决方案

This problem happens because Android Platform (android.jar) already contains JUnit classes. IDEA test runner loads these classes and sees that they are from the old JUnit, while you are trying to use annotated tests which is a feature of the new JUnit, therefore you get the error from the test runner.

The solution is simple, 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. Now the test runner will be happy as it loads the new JUnit version.

这篇关于带有 Junit 4.7 的 IntelliJ IDEA &quot;!!!预计 JUnit 3.8 版或更高版本:"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆