score:37

Accepted answer

Make sure your eclipse environment is using JUnit 4. JUnit 3 doesn't make use of annotations (it uses the old extends TestCase style)

There are few things to double check:

Window > Preferences > Java > JUnit

Are you seeing junit4 or junit3 imports? If that looks good, make sure the project itself is using JUnit4 instead of JUnit3.

Right Click on project > Properties > Java Build Path > Libraries

Is JUnit4 included there? Is anything JUnit related there? If JUnit3 is in there, click on it and click Remove. Then click Add Library... and follow the prompts from there to add JUnit again.

Out of curiosity, are the JUnits run outside of eclipse? Like with a mvn install or whatever build target you have for Ant that'll run JUnits

score:-1

Make sure you are using Junit as your testing framwork and not something like TestNg which cover most of Junit's purpose.

score:0

I encountered the same issue and verified all the settings (above mentioned) are fine. A small change (version to 1.5.21.RELEASE from 2.5.0-M2) in pom.xml resolved my issue (below). This Iam able to recreate consistently.

STS Details Version: 3.9.0.RELEASE Build Id: 201707061823 Platform: Eclipse Oxygen (4.7.0)

Pom.xml change

FROM

<modelVersion>4.0.0</modelVersion>
<parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         **<version>2.5.0-M2</version>**
         <relativePath/> <!--  lookup parent from repository  -->
</parent>

TO

<modelVersion>4.0.0</modelVersion>
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        **<version>1.5.21.RELEASE</version>**
        <relativePath /> <!-- lookup parent from repository -->
</parent>

score:3

The way I fixed it is by changing Test runner in the Run Configuration from the default Junit3 to Junit4. Once I made this change I could see the option Junit when I right clicked on the test class and expanded Run Asenter image description here

score:4

Write a simple test case to see if Eclipse works correctly or not. If simple test case can be run, check your testcase, especially import classes.

Or make a try in "Run" -> "Run Configurations",fill the "Test class" as "TeamTest"(full class name). Then click "Run", see what will happen...


Related Query

More Query from same tag