102

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)
Humoyun Ahmad
  • 2,875
  • 4
  • 28
  • 46

2 Answers2

170

There is no difference, from the javadoc:

SpringRunner is an alias for the SpringJUnit4ClassRunner.

ref: https://docs.spring.io/spring/docs/4.3.0.RC2_to_4.3.0.RELEASE/Spring%20Framework%204.3.0.RELEASE/org/springframework/test/context/junit4/SpringRunner.html

StvnBrkdll
  • 3,924
  • 1
  • 24
  • 31
41

@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);
    }

}
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
Joby Wilson Mathews
  • 10,528
  • 6
  • 54
  • 53
  • 7
    this added more information to understand the detail relation between `SpringRunner` & `SpringJUnit4ClassRunner`. – Eddy Dec 24 '18 at 02:39