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.
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.
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.apipackage.Assertions reside in
org.junit.jupiter.api.Assertions.Assumptions reside in
org.junit.jupiter.api.Assumptions.
@Beforeand@Afterno longer exist; use@BeforeEachand@AfterEachinstead.
@BeforeClassand@AfterClassno longer exist; use@BeforeAlland@AfterAllinstead.
@Ignoreno longer exists: use@Disabledor one of the other built-in execution conditions instead
@Categoryno longer exists; use@Taginstead.
@RunWithno longer exists; superseded by@ExtendWith.
@Ruleand@ClassRuleno longer exist; superseded by@ExtendWithand@RegisterExtension