Lettuce:场景大纲

2017-09-23  本文已影响0人  Ailsa的简书

在我们第一个次描述文件-zero.feature,所有的情况是类似的。我们需要一遍遍地重复了大部分内容。
有没有更好的方法来处理这个问题?当一些场景几乎一样,只有一些值不同时?
有的。 :) 你只需要使用场景大纲。
下面给出了一个示例:

Feature: Compute factorial
  In order to play with Lettuce
  As beginners
  We'll implement factorial

  Scenario Outline: Factorials [0-4]
    Given I have the number <number>
    When I compute its factorial
    Then I see the number <result>

  Examples:
    | number | result |
    | 0      | 1      |
    | 1      | 1      |
    | 2      | 2      |
    | 3      | 6      |
    | 4      | 24     |

这种方式,您只需要提供真正不用的值,减少“复制粘贴”的工作,使测试更加清晰。


如果你使用上面的例子改写zero.feature,执行步骤,你会看到你的描述包含了以上五种情况:


使用XML时,你的大纲替代标签可能有相同的名称。如果你需要命名一个大纲的替代变量类似的名称(比如<head>),也许可以考虑用< _head >


上一篇:Lettuce: Multi-line Strings
下一篇:Lettuce: Calling steps from step definitions

上一篇下一篇

猜你喜欢

热点阅读