I have a file Foo.java
which compiles with no errors. But when I add the single line
import static org.junit.Assert.assertNotEquals;
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
I am using JUnit 4.4. junit-4.4.jar
is included in the classpath
for the javac
task.
I have tried running different compiler versions with the flags -Dbuild.compiler=javac1.7
and -Dbuild.compiler=javac1.8
but it makes no difference. I still get the exact same error.
assertNotEquals
is the only static import from Assert that causes this error.
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.
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.