java
sql
html
css
xml
ajax
mysql
linux
xcode
android
ruby-on-rails
regex
objective-c
visual-studio
perl
tsql
delphi
asp
jsp
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.
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.
In context menu of your 'test' directory choose 'Build path' -> 'Use as a source folder'. Eclipse should see your unitTests.java files as a source files. Warning 'No JUnit tests found' occures because there is no unitTests.class files in your 'build' directory
I was facing the same problem and I debugged it to bad examples on the web and internals of junit. Basically don't make your class extend TestCase as some examples show for Junit 4.x. Use some naming convention Test or if you want to have an annotation you can use @RunWith(JUnit4.class).
If you need access to assert methods extend Assert or use static imports.
If your class extends TestCase then even if you use Junit 4 Runner it will be run as 3. This is because in the initialization code there is detection:
See JUnit3Builder and the lines:
boolean isPre4Test(Class<?> testClass) { return junit.framework.TestCase.class.isAssignableFrom(testClass); }
This returns true and the test for junit4 compatibility won't be tried.
Check if your test class extends "TestCase". if so, remove that clause. Your class does not need to extend from "TestCase" class. It's most of the cases I've met.
public class MyTestCase extends TestCase{ @Test public void checkSomething() { //... } } //Result> AssertionFailedError: No test Found in MyTestCase
Following TestCase should be fine.
public class MyTestCase { @Test public void checkSomething() { //... } } //Works fine
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.
@Test
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.
I also faced the same issue while running JUnit test. I resolved this by putting the annotation @Test just above the main test function.
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
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.
I found out that Eclipse seems to only perform JUnit 3 style tests if your test-class extends from TestCase. If you remove the inheritance, the annotations worked for me.
TestCase
Beware that you need to statically import all the required assert* methods like import static org.junit.Assert.*.
assert*
import static org.junit.Assert.*
I also have this issue when pressing on the main view of the java file (Right click -> Run As -> JUnit Test). However, if I right click on the file in the Project Explorer to run JUnit Test, it works (amazing !!). Hope this help
I had the same issue, and none of the previous solutions worked for me. At the end I realized that the cause was that the class with the @Test annotations was an abstract class... After removing "abstract" everything worked fine
No testsuits in JUnit4. Use annotations instead or use old JUnit3 name conventions.
Example:
@RunWith(Suite.class) @SuiteClasses({YourClassWithTests.class})