5

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.

Community
  • 1
  • 1
MatTheWhale
  • 967
  • 6
  • 16
  • can we see the line of code you are trying to invoke it? the line where you actually call the assert method? – dkatzel Aug 24 '15 at 20:30

1 Answers1

7

You are using Junit 4.4. AssertNotEquals wasn't added until 4.11

JUnit 4.11 release Notes

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.

dkatzel
  • 31,188
  • 3
  • 63
  • 67