views:

1007

answers:

2

I'm using Ganymede on Ubuntu Linux and I have junit-4.3.1.jar in my build path. I click File > New > Java > "JUnit 4 Test Case" when I create a new test, but when it's run, Eclipse appears to be using JUnit 3. I believe this is the case because it's ignoring my annotations.

When I remove all test* methods, JUnit complains "No tests found". If I do the same with another test I already created, JUnit runs fine and finds my test named createTask(). So, it appears to be using JUnit 3 at times, and JUnit 4 at others.

How do I force Eclipse Ganymede to use JUnit 4?

A: 

I have 2 suggestions that might help. First, in the Run/Debug configuration, Make sure the JUnit 4 test runner is selected. Next, if this is a plugin project, add the junit4 runtime to the project as a dependency (in the dependencies tab).

AdamC
JUnit 4 is test runner that is selected. And this is a standard Java project; builds to a JAR.
Elliot
How are you launching? Are you creating a run or debug configuration and clicking on it each time, or right-click and run/debug as on the test?
AdamC
right-click either on the file in Project Explorer or in the editing pane.
Elliot
Try setting up a debug or run configuration that you can reuse. Use the down arrow by the debug or run buttons and do a new Junit configuration. Then pick JUnit 4. When you want to re-run it, select the configuration from the drop down.
AdamC
+2  A: 

I figured out the answer via this link:

Spring is apparently incompatible with JUnit 4.3.1 when extending AbstractTransactionalSpringDataSourceTest (or whatever it is). So, I upgraded to JUnit 4.6 (b/c 4.5 has issues) and used the annotation-based configuration, and voila, all is well.

Thank you.

Elliot