oshai
oshai

Reputation: 15355

not all junit tests are running in eclipse

I have a java project in eclipse, when I press the project right click -> run as junit some tests do not run. I attached a picture, see YamiMailSenderTest for example.
When I try to run the tests directly they are running.
I am using eclipse 3.7.2.

enter image description here

and expanded view:

enter image description here

Any idea?

Upvotes: 9

Views: 15222

Answers (7)

user7427029
user7427029

Reputation: 255

in my case, it seems that cause was a combination of multiple factors. The right combination of properties was for me:

  • The test class is declared as public

  • The test methods are declared as public and NOT declared as static:

    public void testToTeXTable() {

despite what Eclipse may say.

  • Run as ... -> Run configurations should declare that (All methods) are tested and that JUnit 5 is used.Correct run configuration

  • The imports in the test file contain the right source for the Annotation @Test, i.e:

    import static org.junit.Assert.*; import org.junit.Test; //import org.junit.jupiter.api.Test;

Upvotes: 0

MTen
MTen

Reputation: 186

Ran into the same problem, my error was that I wrote: public void myMethodName(){ //assertions }

instead of: public void testMyMethodName() { //assertions }

the test before the MyMethodName is important.

Upvotes: 8

Gondlar
Gondlar

Reputation: 53

It's a bit late, but in case anyone finds this via a search engine:

If a Test is run multiple times the results provided by JUnit are indistinguishable for those Tests and thus the results are only displayed for one run. See also the following Eclipse bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=172256

Upvotes: 3

Mike Nakis
Mike Nakis

Reputation: 61969

I had the same problem. Eclipse would only recognize and run 5 out of my 9 tests. After much troubleshooting I found this trick to convince Eclipse to recognize the remaining tests: just open each file, hit space and then backspace to mark it as changed, and save it. Then, Eclipse will recognize it as a test.

Upvotes: 1

CKuharski
CKuharski

Reputation: 314

I had a similar problem. For some reason, the "Run As -> jUnit Test" was always skiping the first test package. I was on an older version of Eclipse and SpringSource.

I moved back to Juno - Version: 4.2.1 and all my test run when I perform: "Run As -> jUnit Test. "

Upvotes: 1

Mawia
Mawia

Reputation: 4310

In jUnit 4, a test case needs to have @Test annotation. The test case can be set to ignore with @Ignore annotation. The whole test class can also be set to ignore by placing the @Ignore annotation right above the class declaration. Note: In jUnit 4 , there is no need to extend Testcase class as in jUnit 3. Everything is in annotation.

I have no idea about jUnit 3 since I use only 4.

Upvotes: 2

CloudyMarble
CloudyMarble

Reputation: 37566

Check if you are excluding tests from run by attributes and check under Run > Run Configurations if your JUnit configuration are excluding any tests.

Upvotes: 2

Related Questions