我有以下设置
我能够使用以下配置运行黄瓜测试,以使用 Maven 故障安全插件测试本地运行的 SpringBoot 应用程序。
注意:配置使用@SpringBootTest注解在运行测试之前启动SubjectUnderTest(SUT)。
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example.bdd.stepdefs")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME,
value = "pretty," +
"html:target/tests-reports/report.html," +
"json:target/tests-reports/report.json," +
"junit:target/tests-reports/cucumber-junit.xml,")
@CucumberContextConfiguration
@ActiveProfiles("local")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class FunctionalIT {
}
我的要求:
-Dspring.profiles.active=local
或-Dspring.profile.active=qa
。 Spring 只能使用该配置文件。到目前为止,我尝试了几种选择,但没有取得多大成功,我面临以下问题:
@SpringBootTest
注释的情况下为远程环境创建另一个测试类,但 @CucumberContextConfiguration
只允许在单个类上使用。@CucumberContextConfiguration
只需要应用于 @SpringBootTest
或 @ContextConfiguration
。知道如何让设置满足上述要求吗?
我可以通过以下更改“部分”解决问题。
package com.example.bdd.config;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@CucumberContextConfiguration
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME,
value = "pretty," +
"html:target/tests-reports/report.html," +
"json:target/tests-reports/report.json," +
"junit:target/tests-reports/cucumber-junit.xml")
public @interface CucumberTestSuite {
}
package com.example.bdd.test;
@CucumberTestSuite
@ConfigurationParameter(key = GLUE_PROPERTY_NAME,
value = "com.example.bdd.stepdefs," +
"com.example.bdd.test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class FunctionalIT {
}
package com.example.bdd.qa;
@CucumberTestSuite
@ConfigurationParameter(key = GLUE_PROPERTY_NAME,
value = "com.example.bdd.stepdefs," +
"com.example.bdd.qa")
@ContextConfiguration
@TestPropertySource("classpath:application-qa.properties")
@ActiveProfiles("qa")
public class FunctionalRemoteIT {
}
尚未解决的问题:
mvn clean verify
时默认禁用运行FunctionalRemoteIT测试,并且仅在设置了spring.profiles.active=qa
时才启用。我尝试使用 Spring
@EnabledIf
,但显然 mvn 故障安全插件没有使用它......它总是执行与模式 *IT.java
匹配的所有测试。