Missing "Run as JUnit Test"

Viewed 46711

I created a JUnit 4 test in Eclipse by right-clicking on a Java class and selecting New JUnit Test Case. When I right-click the test class I get "Run on Server", but not "Run as JUnit Test". I am using Eclipse 3.6.1.

15 Answers

for junit5 jdk8 is needed in build path and project facets.

  1. check whether you have jave 8 or above and configured correct jdk in build path.
  2. check at least @Test is used in your test case class file
  3. Then go to run configuration->select Junit->right click and new configuration->browse the package->select junit5 as test runner.

enter image description here

In case you experience it in maven project add following into pom.xml and reload project using Alt+F5. Tests do not work because old JDK version.

<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Make sure that you include import org.junit.Test; and the tests have @Test before them, I have missed that before when coping some functions from other files.

To solve the situation, a restart of eclipse wasn´t enough in my case, I had to remove and re-add the project to my workspace as well.

If, the configuration is of SpringRunner.class for Junit. Make sure your maven clean install with maven update and refresh is run in your project with right jdk and mavens password/configuration.

Related