IntelliJ IDEA的使用JUnit 4.7"! JUnit版本3.8或更高版本预计:" [英] IntelliJ IDEA with Junit 4.7 "!!! JUnit version 3.8 or later expected:"
问题描述
当我试图运行在的IntelliJ IDEA下面的测试我得到的消息:
! JUnit版本3.8或更高版本预计:
应该指出的是,这是一个的Android 的项目我的工作中的IntelliJ IDEA 9。
公共类GameScoreUtilTest {
@测试
公共无效testCalculateResults()抛出异常{
最后一场比赛的游戏=新的游戏();
最后的球员PLAYER1 =新播放器();
{
最后PlayedHole playedHole =新PlayedHole();
playedHole.setScore(1);
。game.getHoleScoreMap()把(PLAYER1,playedHole);
}
{
最后PlayedHole playedHole =新PlayedHole();
playedHole.setScore(3);
。game.getHoleScoreMap()把(PLAYER1,playedHole);
}
最后GameResults gameResults = GameScoreUtil.calculateResults(游戏);
的assertEquals(4,gameResults.getScore());
}
}
完整的堆栈跟踪看起来是这样的...
! JUnit版本3.8或更高版本的预期:
java.lang.RuntimeException的:存根!
在junit.runner.BaseTestRunner< INIT>(BaseTestRunner.java:5)
在的junit.textui.TestRunner< INIT>(TestRunner.java:54)
在的junit.textui.TestRunner< INIT>(TestRunner.java:48)
在的junit.textui.TestRunner< INIT>(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(本机方法)
在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)
流程完成出口code -3
这个问题是因为Android平台(的android.jar
)已经包含了JUnit类。 IDEA测试运行加载这些类,并认为他们是从旧的JUnit,当你试图使用注解测试它是新的JUnit的功能,因此,你得到的测试运行错误。
解决方法很简单,打开项目结构
| 模块
| 依赖
,并移动的junit-4.7.jar
起来,让涉及的之前 Android 1.6的平台
在classpath中。现在的测试运行会很高兴,因为它加载新的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.
这篇关于IntelliJ IDEA的使用JUnit 4.7&QUOT;! JUnit版本3.8或更高版本预计:&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!