标签:spring-boot testing integration-testing spring java
在我们的项目中,我们通过覆盖IntegrationTest批注中的属性来设置集成测试,如下所示:
@RunWith(SpringJunitClassRunner.class)
@IntegrationTest("server.port:0",
"health.hystrix.enabled:false"
.... other properties ....
)
@ActiveProfile("local","no-swagger")
public class IntegrationTest{
}
但是在spring-boot 1.4中,@ IntegrationTest注解已被弃用. Spring文档建议改用@SpringBootTest批注.
我的问题是如何使用此新注释覆盖属性?
解决方法:
我了解from the docs是您能够覆盖@SpringBootTest内部的属性.
The
@SpringBootTest
annotation also has a properties attribute that
can be used to specify any additional properties that should be
defined in the Environment. Properties are now loaded in the exact
same way as Spring’s regular@TestPropertySource
annotation.
And also the javadoc of @SpringBootTest
says:
@AliasFor(value="value")
public abstract String[] properties
Properties in form
key=value
that should be added to the Spring
Environment before the test runs.Returns: the properties to add
因此,只需覆盖@SpringBootTest批注内的属性.
@SpringBootTest(properties={"server.port=0"})
标签:spring-boot,testing,integration-testing,spring,java 来源: https://codeday.me/bug/20191111/2022452.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。