Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit error: Class names, 'org.junit.runner.JUnitCore', are only accepted if annotation processing is explicitly requested

After compiling the java file without errors, when I try to run the class with the test units with the following command:

javac -cp .:junit-4.12.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore NameOfTheClass

I get the following error:

error: Class names, 'org.junit.runner.JUnitCore,DigPowTest, NameOfTheClass', are only accepted if annotation processing is explicitly requested

Any idea?

Thanks in advance!

like image 273
João Ferreira Avatar asked Sep 03 '25 07:09

João Ferreira


1 Answers

I got this error too, and thought I would post a slightly more complete answer as there have been a few visits to this question since it was posted.

There is a near duplicate of this question here: javac error: Class names are only accepted if annotation processing is explicitly requested. However, this question came up first for me on google, as my error message matched Joao's more closely (it relates to the junit framework).

Lawrence's answer above assumes that the poster was wanting to compile, but this is not the case as Joao states in his original question (and later in his comment). He had already compiled and was wanting to run the programme, but made a typo with javac in place of java. As javac expects a filename ending '.java' as standard input, it spits out the error: Class names...annotation processing... error message in response.

So if you are getting this message, when trying to run your test code, then you have probably mistyped the command.

P.S. I would have put this in a comment but do not have the reputation.

like image 136
pandamonium Avatar answered Sep 04 '25 21:09

pandamonium