Import org.junit.Test throws error as “No Test found with Test Runner ”JUnit 5“” [duplicate]

夙愿已清 提交于 2021-02-11 14:29:36

问题


If I import org.junit.Test then on running JUnit, it gives me an error as "No Test found with Test Runner JUnit 5".

Instead if I import org.junit.jupiter.api.Test then I can run JUnit test.


回答1:


This org.junit.Test is a JUnit 4 annotation. A Junit5 test runner will not discover a test annotated with org.junit.Test.

A Junit5 test runner will discover a test annotated with org.junit.jupiter.api.Test.

So, this explains why you get "No Test found with Test Runner JUnit 5" when attempting to run a test context which does not contain any tests annotated with org.junit.jupiter.api.Test.

It sounds like you might be migrating from Junit4 to Junit5. If so, there are several changes you'll need to come to terms with. The Junit5 docs offer some useful tips including:

Annotations reside in the org.junit.jupiter.api package.

Assertions reside in org.junit.jupiter.api.Assertions.

Assumptions reside in org.junit.jupiter.api.Assumptions.

@Before and @After no longer exist; use @BeforeEach and @AfterEach instead.

@BeforeClass and @AfterClass no longer exist; use @BeforeAll and @AfterAll instead.

@Ignore no longer exists: use @Disabled or one of the other built-in execution conditions instead

@Category no longer exists; use @Tag instead.

@RunWith no longer exists; superseded by @ExtendWith.

@Rule and @ClassRule no longer exist; superseded by @ExtendWith and @RegisterExtension



来源:https://stackoverflow.com/questions/55017389/import-org-junit-test-throws-error-as-no-test-found-with-test-runner-junit-5

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