Cucumber 条件输入?

Cucumber 条件输入?,cucumber,cucumber-jvm,Cucumber,Cucumber Jvm,我正在尝试为我们的应用程序的一部分编写Cumber测试(我对Cumber完全不熟悉,而且编写验收测试),我在测试中有一个步骤,我想做两件不同的事情之一。我希望它要么检查特定值,要么检查系统默认值 这就是我想到的 Scenario Outline: English News Given with the locale is set to '<language>' When a user views the page Then they see the <image&g

我正在尝试为我们的应用程序的一部分编写Cumber测试(我对Cumber完全不熟悉,而且编写验收测试),我在测试中有一个步骤,我想做两件不同的事情之一。我希望它要么检查特定值,要么检查系统默认值

这就是我想到的

Scenario Outline: English News
  Given with the locale is set to '<language>'
  When a user views the page
  Then they see the <image> image


Examples:
  | language | image        |
  | en-gb    | default      |
  | fr       | "french.png" |
这是正确的方法吗?我的TL建议我实际上应该只使用一步定义,并将“default”作为输入传递,然后在步骤定义内执行条件检查,如下所示:

@And("^they see the \"(.*)\" image$")
public void checkImage(String image) throws Throwable {
  if ("default".equals(image)){
    // check for system default
  } else {
    // check for specific value from the input
  }
}

哪种方法是正确的?非常感谢您的帮助。

您的默认图像必须有真实姓名,对吗?那么为什么不验证它的真实名称呢?因为“默认”可以是任何东西,所以不是每个人都能理解同一件事


如果你这样做,实际上你只需要一个步骤。我不会用if支票,我会用真名。您可以在示例表中添加注释,说明第一个值是默认值,这样团队中的每个人都可以清楚地看到

默认值确实有一个真实的名称,但它只出现在实际的前端页面中(我们的测试没有触及UI层),因此默认值的实际底层数据只是一个空白字符串(本质上,UI说如果不是空白,则显示值,否则显示xyz.png)。有些人会不同意,但在我看来,即使是这样的小逻辑也不应该出现在UI中。因为无论如何,您需要在控制器中有一些逻辑来返回字符串(无论是实名还是空),所以您也可以从后端返回实际的默认值。这样,所有案例的逻辑都在同一个位置,而不是分散在UI和后端之间。
@And("^they see the \"(.*)\" image$")
public void checkImage(String image) throws Throwable {
  if ("default".equals(image)){
    // check for system default
  } else {
    // check for specific value from the input
  }
}