@@ Given或@When黄瓜注解引发与春季靴子配置有关的错误

问题描述 投票:1回答:1

我正在编写黄瓜BDD测试用例。黄瓜的所有依赖项都包含在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 /文件夹中

我正在编写黄瓜BDD测试用例。 pom.xml io.cucumber

...
spring-boot cucumber bdd
1个回答
0
投票

如果我在我的步骤定义文件中评论@Given子句,那么我不会得到与@SpringBootConfiguration相关的错误

如果您在类中没有用上下文配置注释的步骤定义,则Cucumber根本不会检测到任何上下文配置,并且会退回到GenericApplicationContext

© www.soinside.com 2019 - 2024. All rights reserved.