The import org.springframework.test.context.junit4.SpringJUnit4ClassRunner cannot be resolved

You need to add a dependency on spring-boot-starter-test:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

Now, if you are using latest spring-boot, 1.5.2 RELEASE, @SpringApplicationConfiguration is no longer available, instead you must use @SpringBootTest. Reference here(@spring boot starter test in Spring Boot)


Gradle

In gradle this would be done by adding

testCompile("org.springframework.boot:spring-boot-starter-test")

to the dependencies block as in:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("junit:junit")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

After that it should be possible to write an import statement at the top of your class

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

Allowing you to use the annotation:

@RunWith(SpringJUnit4ClassRunner.class)
public class MyAppTest {

}