首页 > 解决方案 > 与黄瓜一起使用宁静时无法读取应用程序 yaml

问题描述

我有一个 runner 类,它作为入口点并使用CucumberWithSerenity.class.

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "src/test/resources")
public class CucumberIntegrationTest {
}

我创建了一个供 stepdef 类使用的基类,

这是我的 stepdef/glue。

public class StepDefs extends SpringIntegrationTest {

@Value("${config.value}")
  private String configValue;

  @When("^the client calls /version$")
  public void the_client_issues_GET_version() throws Throwable {
    String s = configValue;
  }

  @Then("^the client receives status code of (\\d+)$")
  public void the_client_receives_status_code_of(int statusCode) throws Throwable {
    String s = configValue;
  }

  @And("^the client receives server version (.+)$")
  public void the_client_receives_server_version_body(String version) throws Throwable {
    String s = configValue;
  }
}

这是步骤的功能文件。

Feature: the version can be retrieved
  Scenario: client makes call to GET /version
    When the client calls /version
    Then the client receives status code of 200
    And the client receives server version 1.0

我的资源文件夹中application.ymlapplication-stg.yml有 configvalue。

config:
  value: SOME_VALUE

但是,我无法读取读取配置,使用以下,它始终为空。

@Value("${config.value}")
  private String configValue;

我错过了什么?

标签: javaspring-bootcucumberspring-boot-testcucumber-serenity

解决方案


推荐阅读