java-未选择Spring Boot测试配置
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-未选择Spring Boot测试配置,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1346字,纯文字阅读大概需要2分钟。
内容图文
![java-未选择Spring Boot测试配置](/upload/InfoBanner/zyjiaocheng/684/84952fba29c742c0b1cd6f6c2410f369.jpg)
我正在为我的应用程序编写集成测试,并且想对测试使用自定义webmvc配置
我的基本包com.marco.nutri中有三个类:
>应用程序(由@SpringBootApplication注释)
> MvcConfig(@Configuration和@EnableWebMVC)
> SecurityConfig(@Configuration和@EnableWebSecurity)
我的测试在br.com.marco.nutri.integration.auth包中:
@RunWith(SpringRunner.class)
@SpringBootTest(classes={Application.class, WebMvcTestConfiguration.class, SecurityConfig.class})
public class ITSignup {
//Test code
}
我在com.marco.nutri.integration包中有一个测试配置类:
@TestConfiguration
@EnableWebMvc
public class WebMvcTestConfiguration extends WebMvcConfigurerAdapter {
//Some configuration
}
但是,当我运行测试时,将选择MvcConfig.class而不是WebMvcTestConfiguration.class
我究竟做错了什么?
解决方法:
您可以使用@Profile(“ test”)注释测试配置,并使用@Profile(“ production”)注释您的真实配置
并在属性文件中添加属性spring.profiles.active = production,并在测试类中添加@Profile(“ test”).因此,当您的应用程序启动时,它将使用“生产”类,而在测试星级时,它将使用“测试”类.
从文档
Unlike regular @Configuration classes the use of @TestConfiguration
does not prevent auto-detection of @SpringBootConfiguration.Unlike a nested @Configuration class which would be used instead of a
your application’s primary configuration, a nested @TestConfiguration
class will be used in addition to your application’s primary
configuration.
内容总结
以上是互联网集市为您收集整理的java-未选择Spring Boot测试配置全部内容,希望文章能够帮你解决java-未选择Spring Boot测试配置所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。