Eclipse keep saying “No tests found with test runner JUnit 5”

杀马特。学长 韩版系。学妹 提交于 2019-12-01 06:24:05

Your test class is currently based on JUnit 4 since it uses annotations from the org.junit package.

Thus, to get it to run as a JUnit 4 test class in Eclipse, you need to select the JUnit 4 Runner in the "Run Configuration". Click on the tiny arrow (pointing down) next to the green circle with a white arrow in it (at the top of the Eclipse IDE). There you should see your test class, and by selecting that you can switch between the JUnit 4 and JUnit 5 runners.

On the other hand, if your goal is to write a test using JUnit Jupiter (i.e., the programming model for JUnit 5), you'll need to switch from annotations in org.junit to org.junit.jupiter.api.

Take a look back to your imports.

You imports import org.junit.Test; (Used for run test cases with JUnit 4)

You need to import import org.junit.jupiter.api.Test; to run tast case with JUnit5.

In Eclipse 2019-09 (4.13) is a bug that can cause the "No tests found with test runner 'JUnit 5'" error: https://bugs.eclipse.org/bugs/show_bug.cgi?id=551298

I added the following dependency to my project and it worked for me:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-commons</artifactId>
    <version>1.5.2</version><!--$NO-MVN-MAN-VER$-->
    <scope>test</scope>
</dependency>

You are using JUnit 4 annotations with JUnit 5 dependencies. If you want to use JUnit 5 you should replace:
'@Before' with '@BeforeEach'
'@AfterEach' with '@AfterEach'
'@BeforeAll' with '@BeforeAll'
'@AfterAll' with '@AfterAll'

Here is more about JUnit 5 annotations https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations/

This happened to me because my test method was declared as private and JUnit could not detect it. After I made it public it worked as expected, of course with @Test annotation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!