spring boot 1.4.0以下不直接支持@SpringBootTest註解
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Slf4j
public class CustomerTest {
@Autowired
private BaseManager baseManager;
@Test
public void test() throws IOException {}
}
如果想使用該註解,需要引入其他jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.11.RELEASE</version>
</dependency>
spring boot 1.4.0以上在spring-boot-starter-test已加入以上兩個jar,只需
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
我們點進去該依賴,可以看到爲什麼不需要再引入以上兩個jar了