【问题标题】:BBD features with dates and timestamps带有日期和时间戳的 BBD 功能
【发布时间】:2014-07-21 14:00:54
【问题描述】:

如何最好地处理特征定义中的时间戳(日期、时间等)?

示例

功能:消息状态

    In order to record activty on a message

    As a administrator

    I want to log when a message was created, delivered, and read by an end user

场景大纲:消息创建状态

    Given I have configured an e-mail service

    When I perform a send operation with a message body of:

    """
      James,

      Fancy meeting for lunch?
    """       
   Then I should see a new message with a created timestamp of ?????

环境

操作系统:Linux/Mac

语言:Python 2.7.5

BDD 框架:lettuce.py

【问题讨论】:

  • 我的回答有帮助吗?您找到解决问题的方法了吗?

标签: cucumber bdd acceptance-testing lettuce user-acceptance-testing


【解决方案1】:

发送消息后,我假设用户会看到消息摘要屏幕。如果是这样,您可以将测试重写为:

Given I have configured an e-mail service
When I send a message
Then I should see a sent message summary
And that it was sent in a timely manner

我要做的第一件事是断言消息摘要符合预期,例如也许您会显示消息中的前二十个字符。如果您不这样做,请忽略此建议。

接下来,您的应用程序可能对发送消息需要多长时间有非功能性要求(例如,发送消息最多需要十秒)。我首先要做的是在“当我发送消息时”步骤定义中记录发送消息的时间。然后在“并且它是及时发送的”步骤定义中,我会断言显示的消息时间在发送时间的 10 秒内有一个值。

关键是发送电子邮件所花费的时间(几乎总是)是不确定的,因此测试它是在特定时间范围内发送的原因。

请注意,我假设您的发送消息过程是同步操作,即程序执行仅在消息发送后才会进入摘要页面,尽管情况可能并非如此(并且通常是异步过程)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-16
    • 1970-01-01
    • 2017-08-20
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    相关资源
    最近更新 更多