0
votes

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
So what's the question?Mureinik

1 Answers

6
votes

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