SpringBoot集成测试
Spring Boot集成单元测试
1.依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope>
</dependency>
2.创建测试
在src
下创建test
,在test
下创建java
,在该java
目录下创建同启动类所在一致的包,例如com.demo
,然后就可以在这个包下创建测试案例了:
//加载spring整合junit专用的类运行器
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
// 存在除application外多个配置文件可以指定,这里会加载
// application-local.yml以及application-dynamic-db.yml
@ActiveProfiles({"local", "dynamic-db"})
public class DemoTest {@Autowiredprivate GoodBoy goodBoy;@Testpublic void test1(){}
}