views:

2286

answers:

7

Hello , my java test worked well from Eclipse ,I do not know I relaunch test from run menu and then have the following message:

No tests found with test runner 'JUnit 4'

In the .classpath file I have all jar files, and at the end have :

<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

please help!

A: 

Is your Eclipse project maven based? If so, you may need to update the m2eclipse version.

Just a quick note: I have a project in Eclipse which is maven-based, and generated initially using the "new maven project" wizard in Eclipse. I'm using JUnit 4.5 for the unit tests, and could quite happily run the tests from the command line using maven, and individual tests from Eclipse using run as JUnit test.... However, when I tried to run all of the tests in the project by invoking run as JUnit test... on the project root node, Eclipse complained "no tests found with test runner junit 4". Solved by upgrading m2eclipse to the latest stable development build from the m2eclipse update site (specifically, I upgraded from version 0.9.8.200905041414 to version 0.9.9.200907201116 in Eclipse Galileo).

From here: http://nuin.blogspot.com/2009/07/m2eclipse-and-junit4-no-tests-found.html

Bruno Rothgiesser
I do not understand, I do not think that it is related to eclispe version , my test worked yesterday and not the case now because of Junit launch popup is there a way to restet to my first configuration ?
Does your test work with a Junit3 Runner ?
phtrivier
Lamisse, I'm confused too. I suggest that you update your question to explain when the unit test run works and when it does not work.
Bruno Rothgiesser
A: 

May be your JUnit launch configuration was for a individual test class, and you somehow changed that config to "run all tests in a source folder, package or project"

But that could trigger the "No tests found with test runner 'JUnit 4'" error message.

Or you did a modification in your test class, removing the @Test annotation.
See this wiki page.

VonC
@Test is here, the message is : could not faind main class toto.lolo.testrunner (which is specified in the run configuration )
@lamisse: so, some kind of classpath issue? or a syntex issue: it should be `toto.lolo.Testrunner` and not `toto.lolo.testrunner` ('T')
VonC
@lamisse : is "toto.lolo.Testrunner" the actual name of your TestRunner class ? Is it something you wrote ? Is the project / jar containing it in the classpath of your launch configuration ?
phtrivier
+4  A: 

When we get these errors it seems like Eclipse is just confused. Restart Eclipse, refresh the project, clean it, let Eclipse rebuild it, and try again. Most times that works like a charm.

JamesG
This is incredibly unsatisfying.
dlamblin
+1  A: 

Hey, this just happened to me. I found your question while looking for the answer myself. Rebuilding or restarting Eclipse didn't help, I got it solved by renaming one of the test methods to start with "test..." (JUnit3 style) and then ALL tests are found. I renamed it back to what it was and it still works.

Hope that helps.

Germán
A: 

Hello,

I tried the solution from Germán. It worked for all the method from my class but i have a lot of classes in my project.

So I tried removing from build path and then re-adding it. It worked perfectly.

Hope it helps.

Footix29
A: 

This happened to me too. I found that in Eclipse I didn't make a new Java Class file and so that's why it wasn't compiling. Try copying your code into a java class file if it's not already there and then compile.

Anna
A: 

Even if your function is not annotated with @Test you would face this issue.

Harpreet