Posted at

SpringのJUnitで@Autowiredできない!

More than 1 year has passed since last update.


以下のアノテーションをつける

@RunWith(SpringRunner.class)

@SpringBootTest


TestApplicationTests.java

import org.junit.Test;

import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestApplicationTests {

@Test
public void contextLoads() {
}

}