JUnit Tests not running in Eclipse

55,231

Solution 1

In my case it was because Eclipse started using JUnit 5 as the test runner. I resolved the issue by going to Run Configuration and selecting the older test runner: test config

Solution 2

Not sure if your problem is already solved.

I had a similar issue which got solved when I corrected the Project -> Properties -> Java Compiler -> JDK Compliance settings.

I had a conflict between 1.5 and 1.6. When I reverted back to 1.5 (which was the current active JRE), my JUnits started working again.

Solution 3

My case is different but I got the same junit error. I had conflicts in junit dependences using:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <scope>test</scope>
</dependency>

Having this, you have to use

import org.junit.jupiter.api.Test;

instead of

import org.junit.Test;

Solution 4

One possibility is that Eclipse's JUnit runner is confused by the presence of the main method and is running that rather than the test methods.

Try commenting out the main method. It shouldn't be there at all, IMO.

(By the way, the main method doesn't look right to me. I'd have thought it would instantiate a TestSuite with the unit test classes as parameters, but you seem to be giving it the class under test. That won't have any "test" methods, which would explain why no tests are being run ...)

Solution 5

Like already mentioned, remove the main method, might helpt. Any particular reason for extend from TestCase that is Juni3 if I remember correctly? Did you try Junit 4 by using @Test annotation

for instance:

@Test
public void testSomething() {
     //you stuff
}
Share:
55,231
Dharman
Author by

Dharman

Stack Overflow elected moderator since 28th March 2022. Warning: You are wide open to SQL Injections and should use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input! Even when your queries are executed only by trusted users, you are still in risk of corrupting your data. Escaping is not enough!

Updated on October 19, 2021

Comments

  • Dharman
    Dharman about 1 year

    This is a snapshot of the eclipse editor. You can see the test and the JUnit tab. When I try to run the test, it says Terminated.

    enter image description here

    Anybody know what is going on here?

    • Hakan Serce over 10 years
      How do you run your test? I mean through the main method in your BasicInfoTest class or through right clicking in the eclipse package explorer?
    • Admin
      Admin over 10 years
      I am right clicking and running as JUnit Test.
    • Ramesh Kotha
      Ramesh Kotha over 10 years
      that looks like a test suite for me, can u run it as a Junit Test Suite rather than Junit Test case..
  • betontalpfa
    betontalpfa almost 6 years
    I have seen the same, but when I set back 1.6 (and 1.8) it worked too. So revert back to 1.5 and then set it again to 1.6
  • Benyam Ephrem
    Benyam Ephrem almost 3 years
    Thanks! I Added it to my Module Path and had no idea what was going on