@RunWith
The core class of the spring-test is SpringJUnit4ClassRunner (lately known as SpringRunner)
Loads Spring Test context
Caches an ApplicationContext across JUnit 4 test methods.
Annotate the test class with
@RunWith(SpringJUnit4ClassRunner. class) or @RunWith(SpringRunner.class).
Also annotate the class with @ContextConfiguration to tell the runner class where the bean definitions come from
Using @ContextConfiguration without any attributes, spring will search for a file named {testClassName}- context.xml in the same location as the test class and load bean definitions from there if found. so, not only this annotation can be used with XMl configuration files, but it is specific to JUnit 4.
Junit 5
@ExtendWith
@ExtendWith(SpringExtension. class).
The SpringExtension class integrates the Spring test context into the Junit 5 ‘s Jupiter programming model.
It runs the tests, it also creates the application context
The problem with Runners
You could not run multiple runners at the same time with Junit 4. With Extensions in Junit 5, you can now run multiple extensions at the same time.
Use @ExtendWith instead of @RunWith