4

I have a strange issue with JUnit 4 tests in Eclipse 3.5 that I couldn't solve - any hints gratefully received!

Initially: I had a test suite working properly, with 100+ tests all configured with JUnit 4 annotations. I'd run these typically by right clicking on my source folder and selecting "Run as JUnit test". All worked perfectly.

Now: When I try to run the test messages all I get is an error "No tests found with test runner 'JUnit 4'".

Any idea what is happening? I simply can't work out what could have changed to make this fail.

My guess is that it is some configuration issue based on the build path or class path?

mikera
  • 105,238
  • 25
  • 256
  • 415
  • Additional info: I'm using the following plugins: EGit, Subversion client (Subclipse), Counterclockwise for Clojure, ASM Framework, Findbugs, Metrics plugin – mikera Jun 08 '10 at 15:22
  • Additional info: doesn't seem to be a problem with JUnit itself as tests still run fine in other projects. Really does seem to be project configuration related but I can't work out what dependency could be missing.... – mikera Jun 08 '10 at 15:25

5 Answers5

4

Had this issue too, doing a "Project --> Clean" and then trying to run the unit tests as usual already did it!

Akku
  • 4,373
  • 4
  • 48
  • 67
2

I solved a problem like this differently. None of these solutions worked for me. My project is a Google Web App project, a Maven Project, and a JREbel project... so any of these could have been messing with my setup.

I also found that I could not run any classes with a main() method using Run As -> Java Application. That resulted in a ClassNotFoundException.

My solution was to create a new Web Application Project and copy in all the source and set it up again. Now both Java Application and JUnit Test work as expected

John Patterson
  • 497
  • 3
  • 11
1

funniest answer for this question.

Change the test name to start with "test"

For example,

@Test public void checkForTwoStringTest(){....}

Change to

@Test public void testCheckForTwoString

This did work like a miracle.... :-)

Pratap Dessai
  • 139
  • 2
  • 3
1

My first couple of thoughts (without seeing some example test code):

No tests found with test runner 'JUnit 4'

A lot of suggestions state to restart Eclipse and clean project. In my experience, sometimes eclipse gets stuck in a mode where it thinks I am trying to do a hybrid run between JUnit 3 and 4, so naming the '@Test' method with the old verbiage of naming it 'test...' sometimes works.

Also if you have any other plugins, i.e. m2eclipse, or other that you have recently added, this could effect your situation as well. If anything you have recently added uses its own version of JUnit, this could cause issues.

Some sample test code, might help with further investigation.

Community
  • 1
  • 1
Nick Vallely
  • 1,396
  • 1
  • 13
  • 18
  • Thanks - I did check that thread but none of the tips there seemed to work (restart eclipse or clean project didn't work, I'm not using Maven). – mikera Jun 08 '10 at 15:20
  • Also most of the tests are already named something like "@Test public void testXXX()" so probably isn't the 3/4 confusion issue. – mikera Jun 08 '10 at 15:23
  • Hmm... try getting rid of the 'test' keyword and running just one test case individually, does that work? – Nick Vallely Jun 08 '10 at 15:34
  • Also, since it seems to be a project configuration issue, do you have the same 'working directory' between the 2 projects for your JUnit configuration (arguements tab)? I believe it defaults to ${workspace}. – Nick Vallely Jun 08 '10 at 15:37
  • I have ${workspace_loc:ProjectName} as the working directory (which is the default). All the code is then under the src subdirectory. Could that be an issue? – mikera Jun 10 '10 at 21:59
0

I never found out the real cause of this issue but an upgrade to Eclipse 3.6 finally solved it.

mikera
  • 105,238
  • 25
  • 256
  • 415