JUnit cannot find tests in Eclipse

I have a strange problem with JUnit 4 tests in Eclipse 3.5 that I could not solve - greetings are gratefully received!

Initially: I had a test suite that worked correctly, with 100+ tests configured with JUnit 4 annotations. I would run them by right-clicking on the source folder and selecting Run as JUnit Test. Everything worked perfectly.

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

Any idea what is going on? I just canโ€™t understand what could have changed to prevent this from happening.

I assume this is some kind of configuration problem based on build path or class path?

+4
source share
5 answers

I never found the real cause of this problem, but updating to Eclipse 3.6 finally solved it.

0
source

If this problem also ran, "Project โ†’ Clean", and then tried to run unit tests, as usual, already did it!

+4
source

I solved this problem 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 them could be confused with my setup.

I also found that I could not run any classes using the main () method using Run As -> Java Application. This threw a ClassNotFoundException.

My solution was to create a new web application project and copy it into all the source code and configure it again. Now both Java Application and JUnit Test are working as expected

+2
source

My first couple of thoughts (not seeing the sample test code):

No tests found with test runner "JUnit 4"

Many suggestions include restarting Eclipse and cleaning up the project. In my experience, sometimes eclipse gets stuck in the mode when it thinks I'm trying to perform a hybrid run between JUnit 3 and 4, so calling the @Test method an old wording calling it "test ..." sometimes works.

Also, if you have any other plugins, i.e. m2eclipse or others that you recently added, this may also affect your situation. If something you have recently added uses its own version of JUnit, this can cause problems.

Some sample test code may help further research.

+1
source

The funniest answer to this question.

Change the name of the test to start with "test"

For instance,

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

Change to

@Test public void testCheckForTwoString

It really worked like a miracle .... :-)

+1
source

Source: https://habr.com/ru/post/1312221/


All Articles