What is the difference between SpringJUnit4ClassRunner and SpringRunner
30,376
Solution 1
There is no difference, from the javadoc:
SpringRunner is an alias for the SpringJUnit4ClassRunner.
Solution 2
@RunWith(SpringRunner.class)
tells JUnit to run using Spring’s testing support. SpringRunner
is the new name for SpringJUnit4ClassRunner
, it’s just a bit easier on the eye.
SpringRunner
is only available on spring-test 4.3.
SpringRunner
class extends SpringJUnit4ClassRunner
.
Source code of SpringRunner
is
package org.springframework.test.context.junit4;
import org.junit.runners.model.InitializationError;
public final class SpringRunner extends SpringJUnit4ClassRunner {
public SpringRunner(Class<?> clazz) throws InitializationError {
super(clazz);
}
}
Author by
Humoyun Ahmad
Passionate about everything related to Science, Technology, Engineering and Math.
Updated on July 08, 2022Comments
-
Humoyun Ahmad almost 2 years
Whenever I see a blog post related to Spring testing I see either of these classes but do not understand the real difference:
@RunWith(SpringRunner.class) @RunWith(SpringJUnit4ClassRunner.class)