Springboot单元测试
我们如何使用springboot来进行可以读取到配置的测试呢?
引入测试依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
在测试类上添加@RunWith(SpringRunner.class)和@SpringbootTest注解
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringTest {
@Value("${spring.redis.port}")
private int port;
@Test
public void testGetPort() {
System.out.println(port);
}
}
这样就可以读取到applicaiton.property的配置文件