assertNotEquals静态导入导致编译出错

编程入门 行业动态 更新时间:2024-10-26 11:23:51
本文介绍了assertNotEquals静态导入导致编译出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个文件 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静态导入导致编译出错

本文发布于:2023-10-19 19:16:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508503.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   assertNotEquals

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!