2016-07-15 185 views
-3

我有一些项目的单元测试,我在intellij想法中执行。如果我使用java 7,测试工作正常,但是当我将java从7更改为8时,所有单元测试都会出现此错误堆栈跟踪。JUNIT4在java下无法工作8

java.lang.IllegalArgumentException 
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119) 
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 

什么是这个问题的根本原因?

更新 - 添加测试类和标题的导入。

import junit.framework.TestCase; 
import mockit.Expectations; 
import mockit.NonStrictExpectations; 
import mockit.Mocked; 

public class PrepareModule extends TestCase { 
+1

看起来问题不在JUNIT它是在intellij – Jens

+0

请添加一些代码。 – cssGEEK

+0

您是否使用最新版本的IntelliJ? – Tom

回答

0

你说你正在使用的JUnit 4,但您的代码段包括:

import junit.framework.TestCase; 

public class PrepareModule extends TestCase { 
} 

这是通过测试的JUnit的3风格

试试这样说:

import org.junit.Test; 

public class PrepareModule { 
    @Test 
    public void someTest() { 
    } 
} 
+0

仍然得到相同的错误。 –

+1

你可以检查JUnit 3的依赖关系并删除它们吗?这个答案的方法似乎是正确的。 – vikingsteve

0

OK,wit^h新鲜的眼睛看着你的堆栈跟踪:

java.lang.IllegalArgumentException 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 

假设这是整个堆栈,我看包仅从:

  • java.lang
  • sun.reflect
  • com.intellij

这告诉我JUnit无关与问题;也可能是问题出在顶部的类(或底部为准)堆栈:com.intellij.junit4.JUnit4IdeaTestRunner

,如果你可以尝试不同的JUnit运行,如from command line

java org.junit.runner.JUnitCore <test class name> 
0

什么版本JMockIt你使用?一些老版本的JMockIt与Java 8不兼容。

我和你几乎有同样的问题(一切都一样,除了我的测试没有扩展TestCase)。我通过升级JMockIt 1.0 - > 1.14解决了我的问题。

0

我觉得这个问题是由IDEA引入的。

+0

这不提供问题的答案。一旦你有足够的[声誉](http://stackoverflow.com/help/whats-reputation),你将可以在任何帖子上[评论](http://stackoverflow.com/help/privileges/comment)。另外检查这[我可以做什么,而不是](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an-i-do-instead )。 – thewaywewere

相关问题