1
Given a stock threshold of 10.0
When stock threshold is set to 10.0
Then threshold result should be 10.0

在上述步骤中,我想使用预定义变量而不是常量值 10.0。喜欢,

Given a stock threshold of <thresholdValue>
When stock threshold is set to <thresholdValue>
Then threshold result should be <thresholdValue>

此预定义变量可以是所有故事的全局变量。并且可以在步骤类或故事文件本身中初始化该值。这种实现可以在JBehave中完成吗?

4

1 回答 1

0

如果每个故事中的阈值相同,那么我不会将其硬编码到步骤中。如果该值具有重要意义,10.0那么我会给它一个对业务有意义的名称:

Given an average stock threshold
Given a nominal stock threshold

或者只是一起放弃价值并简化每个步骤:

Given a stock threshold
When the stock threshold is set
Then the stock threshold should be met

如果每个步骤都有一个硬编码值是绝对必要的,那么要么复制并粘贴该值并直接使用它,要么在每个场景中使用不同的值。通常,测试数据的差异比一遍又一遍地使用相同的测试数据要好。

基本上如果10.0没有任何业务意义,则省略该值并让该值在步骤定义中硬编码,或者复制并粘贴该值。不要在这上面浪费太多心思。

于 2020-03-11T11:12:00.597 回答