我有一个文件 Foo.java 这没有错误编译。但是,当我添加了一行
I have a file Foo.java which compiles with no errors. But when I add the single line
import static org.junit.Assert.assertNotEquals;这导致以下错误从我的Ant构建:
This causes the following error from my ant build:
compileTests: [javac] Compiling 27 source files to C:\example\bin [javac] C:\example\src\Foo.java:7: error: cannot find symbol [javac] import static org.junit.Assert.assertNotEquals; [javac] ^ [javac] symbol: static assertNotEquals [javac] location: class [javac] 1 error我使用JUnit 4.4。 的junit-4.4.jar 包含在的classpath 为的javac 任务。
我曾尝试与标志运行不同的编译器版本 -Dbuildpiler = javac1.7 和 -Dbuildpiler = javac1.8 ,但它并没有区别。我仍然得到确切的同样的错误。
I have tried running different compiler versions with the flags -Dbuildpiler=javac1.7 and -Dbuildpiler=javac1.8 but it makes no difference. I still get the exact same error.
assertNotEquals 是断言只有静态导入导致此错误。
assertNotEquals is the only static import from Assert that causes this error.
我已经看到了这个帖子Java静态导入引起编译错误。可能的编译器错误?我试图导入断言自身和prepending每个断言与断言语句。喜欢这个职位建议。我得到了同样的错误,这一次的方法调用 Assert.assertNotEquals()而不是import语句。
I have already seen this post Java static import causing compile error. Probable compiler bug? and I tried importing Assert on its own and prepending each assert statement with Assert. like this post suggested. I got the same error, this time at the method call for Assert.assertNotEquals()instead of the import statement.
导入成功编译和运行Eclipse的,但是。
The import successfully compiles and runs on Eclipse, however.
有没有人对这个原因的任何想法?我希望去的这条底线,而不必实施一种变通方法解决方案。
Does anyone have any ideas about the cause of this? I'd like to get to the bottom of this instead of having to implement a workaround solution.
推荐答案正在使用JUnit 4.4。 AssertNotEquals 未添加至4.11
You are using Junit 4.4. AssertNotEquals wasn't added until 4.11
的JUnit 4.11发行说明
如果您更新到最新的JUnit罐子。编译错误应该消失。 Eclipse是可能使用它自己的内置版本具有最新的方法。
If you update to the latest JUnit jar. the compiler error should go away. Eclipse is probably using its own built in version that has the latest methods.
更多推荐
assertNotEquals静态导入导致编译出错
发布评论