@ Given или @ Когда аннотация огурца выдает ошибки, связанные с конфигурацией весенней загрузки - PullRequest
1 голос
/ 06 марта 2020

пишу огурец BDD контрольные примеры. Все зависимости огурца включены в пом. 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

1 Ответ

1 голос
/ 06 марта 2020

Если я прокомментирую предложение @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 находится в том же пакете, или добавьте аннотацию @ContextConfiguration к AccessProfileStepDefinition.

...