添加URL
分享

I think I see the problem. You need to have an actual test in the file before Eclipse identifies it as a test case. Try inserting the following:

@Test
public void foo() {
                Thanks for the suggestion.  The file does have tests in it, but Eclipse doesn't recognize it as a JUnit test class.
                    – amaran
                Jun 16 '11 at 1:02
                if it happens again after that change, try restarting Eclipse. Sometimes the menu items will stop showing under Run As or Debug As or both, and restarting fixes the problem.
                    – Andy Thomas
                Jun 16 '11 at 1:09
                Thanks Andy!  That did the trick.  Do you know how to hide "Run on Server".  It's always there, but I never use it.
                    – amaran
                Jun 16 '11 at 1:29
        

In my case, the problem was different. I was converting a TestNG test to JUnit. The @Test annotation was satisfied by the TestNG import, but that was the wrong annotation. I removed the TestNG import and added the JUnit import for @Test, and the right-click menu option to run as a JUnit test appeared.

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>
  • check whether you have jave 8 or above and configured correct jdk in build path.
  • check at least @Test is used in your test case class file
  • Then go to run configuration->select Junit->right click and new configuration->browse the package->select junit5 as test runner.
  • I ran into these symptoms when importing an existing project into a Kepler-based Eclipse IDE for Java Developers version.

    Importing the project into a Luna-based Eclipse IDE for Java EE Developers correctly set set it to a Java project (project icon now includes that little J) and now allows running JUnit tests.

    The problem was not able to run Junit test from eclipse. Thats why I have given this. – Sajan Chandran Feb 28 '12 at 20:34

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

    site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.2.13.36069