您可以在某个步骤中同时使用@Given 和@And 吗?
Can you use both @Given and @And for a certain step?
我有几个共享步骤定义的测试。例如:
Scenario: test1
Given that the sky is blue
And that the sun is up
When I go outside
Then I might get a sunburn
Scenario: test2
Given that the sun is up
When I go outside
Then it will be light
"And that the sun is up" 和 "Given that the sun is up" 这两个步骤在实现上是相同的。
我想要的是:
@And("that the sun is up")
@Given("that the sun is up")
public void thatTheSunIsUp() {
// Do some fancy and sunny things.
}
不幸的是,这不起作用。我怎样才能达到同样的效果,而不需要相同步骤的重复方法?
不过我认为你做不到
您反对使用@Repeatable 函数吗?
我的理解是你可以再次使用 @Given 和来自 Java8+ 的 @Repeatable。
不能在 cucumber 中用相同的文本对相同的方法进行两次注释。但是,您可以在特征文件中使用 And
调用带有 @Given 注释的方法。
因此,要么删除 @And 注释,要么更改其中一种情况下的文本。
黄瓜中的每一步都定义为Given
、When
或Then
,但实际上更像是:
// ENTER PSUEDOCODE
@Step("that the sun is up")
public void thatTheSunIsUp() {
// Do some fancy and sunny things.
}
关键字是可互换的,这允许上下文判断它是先决条件 (Given
) 被测操作 (When
) 还是结果 (Then
)。
按原样定义它(没有重复的 @And
部分),您将能够使用 Given
、When
、Then
、And
, But
和 *
在你的特征文件中作为关键字,并且 cucumber 的后端应该与你的步骤相匹配,但是你用于定义的应该与它的预期用途相匹配(如前所述款)
我有几个共享步骤定义的测试。例如:
Scenario: test1
Given that the sky is blue
And that the sun is up
When I go outside
Then I might get a sunburn
Scenario: test2
Given that the sun is up
When I go outside
Then it will be light
"And that the sun is up" 和 "Given that the sun is up" 这两个步骤在实现上是相同的。
我想要的是:
@And("that the sun is up")
@Given("that the sun is up")
public void thatTheSunIsUp() {
// Do some fancy and sunny things.
}
不幸的是,这不起作用。我怎样才能达到同样的效果,而不需要相同步骤的重复方法?
不过我认为你做不到
您反对使用@Repeatable 函数吗?
我的理解是你可以再次使用 @Given 和来自 Java8+ 的 @Repeatable。
不能在 cucumber 中用相同的文本对相同的方法进行两次注释。但是,您可以在特征文件中使用 And
调用带有 @Given 注释的方法。
因此,要么删除 @And 注释,要么更改其中一种情况下的文本。
黄瓜中的每一步都定义为Given
、When
或Then
,但实际上更像是:
// ENTER PSUEDOCODE
@Step("that the sun is up")
public void thatTheSunIsUp() {
// Do some fancy and sunny things.
}
关键字是可互换的,这允许上下文判断它是先决条件 (Given
) 被测操作 (When
) 还是结果 (Then
)。
按原样定义它(没有重复的 @And
部分),您将能够使用 Given
、When
、Then
、And
, But
和 *
在你的特征文件中作为关键字,并且 cucumber 的后端应该与你的步骤相匹配,但是你用于定义的应该与它的预期用途相匹配(如前所述款)