当我使用Spring 5(不是Spring )应用程序时,我试图在我的工作流程中应用TDD,但是我的运行测试大约需要45s,这使得我的开发周期非常慢。标准单元测试非常快速,但我有一个测试可以验证Spring上下文配置--它自己需要30多个。
我的想法是在开发周期中每次都禁用这个特定的测试,并不时地运行它--例如,当我用我的应用程序创建一个Docker映像/使用更改进行提交/推送时。
到目前为止,我想出的是:
test.properties中使用它:
app.profile=${build.profile.id}@EnabledIf注释:
@TestPropertySource("classpath:test.properties") @SpringJUnitConfig( class = MainConfiguration.class ) @EnabledIf("#{'${app.profile}‘== 'docker-build'}")公共类SpringConfigTest {.}而且它似乎不起作用--我可能错了,但是当我在@EnabledIf中调用它时,它似乎是不可用的。或者可能我选择了一个错误的路径,并且有更简单的方法来禁用这个特定的测试--我现在以mvn test的身份运行它。我想知道为什么app.profile属性对于@EnabledIf是不可见的。
编辑我发现我可以跳过前两个步骤并在命令行中定义属性:
mvn -Dapp.profile=docker-build test但不知道为什么我不能从test.properties文件中获取属性
发布于 2019-07-12 14:43:02
我相信在本例中,您需要加载@EnabledIf的spring版本的上下文,以便对表达式进行评估。所以应该是:
@EnabledIf(expression = "#{'${app.profile}' == 'docker-build'}", loadContext = true)还请确保在启用筛选的情况下,maven testResources中包含了属性文件:
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>我认为上面应该解决你所面临的具体财产问题。但是,由于这不会跳过加载spring上下文,所以更好的方法可能是在maven配置文件中配置为根据包或测试类名跳过测试--类似于Is there a way to tell surefire to skip tests in a certain package?。
https://stackoverflow.com/questions/56992966
复制相似问题