我正在编写cucumber BDD测试用例
cucumber的所有依赖项都包含在pom.xml中
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.trivago.rta</groupId>
<artifactId>cluecumber-report-plugin</artifactId>
<scope>test</scope>
<version>2.3.3</version>
</dependency>
在我的步骤定义文件中,我包含了SprintBootTest注释
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AccessProfileStepDefinition {
private final Logger log = LoggerFactory.getLogger(AccessProfileStepDefinition.class);
// Location of input payload, which will be used to send request to api server.
private static final String root_folder = "/testdata/bdd/json_for_accessprofile/";
private final static String create_useraccessprofile_payload = root_folder + "create_access_profile_req.json";
@Autowired
private AccessProfileHttpClient httpClient;
@Given("I am cbx system user")
public void i_am_cbx_system_user() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
我得到错误-当我运行测试时
mvn -DAccessProfileFeatureBDDTest clean test
java.lang.IllegalStateException:找不到@SpringBootConfiguration,您需要在测试中使用@ContextConfiguration或@SpringBootTest(classes=…(
如果我在步骤定义文件中注释@Given子句,那么我不会得到与@SpringBootConfiguration 相关的错误
其他文件。低于
package com.igtb.dcp.cbxaccessprofile.bdd;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/features/accessprofile/", plugin = {
"json:target/cucumber-report/cucumber.json", "com.igtb.dcp.cbxaccessprofile.bdd.TestInitialization" })
public class AccessProfileFeatureBDDTest {
}
accessprofile.feature具有该功能,并包含在src/test/resources/features/accessprofile/folder 中
如果我在步骤定义文件中注释@Given子句,那么我不会得到与@SpringBootConfiguration 相关的错误
如果类中没有用上下文配置注释的步骤定义,Cucumber将根本检测不到任何上下文配置,并返回到GenericApplicationContext
。
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
Spring告诉您,您的@SpringBootTest
找不到任何用于构建应用程序上下文的配置。
您必须显式引用用@SpringBootconfiguration
注释的类,或者确保@SpringBootApplication
注释的类在同一个包中,或者向AccessProfileStepDefinition
添加@ContextConfiguration
注释。