springBoot JunitTest的使用以及如何在junit启动前加载

springBoot JunitTest的使用

@SpringBootTest(classes = {Application.class},webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestExecutionListeners(listeners = {TestListener.class, DependencyInjectionTestExecutionListener.class })
@TestPropertySource(locations = {"file:../config/prop.properties"})
public class Test {@Autowiredprivate Service Service;@Testpublic void test(){Service.testMethod("11111111");}}

首先是@TestExecutionListeners 注解,这个注解可以在junit测试开始之前进行设置环境变量或做其他的事情

@TestPropertySource 这个注解可以为environment加载一些配置文件,这些配置文件必须是properties,使用过程中发现yaml解析不了。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部