2013-12-16 87 views
1

我有以下的小黄瓜:同一步骤定义

Given i go to the URL 
And i enter the <NRIC or FIN> as NRIC/FIN 
And i select the option to proceed Next 
And i select the first available available Handset Color 
And i select the option to proceed Next 
And i enter <Full Name> as Name 
When i select the option to proceed Next 

的“I select the option to proceed Next”出现了三次。这应该如何写在Step Definitions Java类文件中?

回答

1

在编写黄瓜场景时,您可以采用命令式或声明式样式。我宁愿写下同样的东西。

Given i go to the URL 
And i enter NRIC/FIN 
And i select the first available Handset Color 
And i enter <Full Name> as Name 
Then I should see that 

因此,这取决于谁将读取您的方案。一个值得阅读的链接是imperative - declarative

3

除了声明性/命令性问题,还有一个关于你描述什么需求的思考。出于这个原因,我发现在示例中包含Scenario:会很有帮助。在给定步骤中获得这些详细信息非常不寻常

您是否正在测试订单的创建(猜测位)?如果是的话那么你的输入/选择步骤应该是Whens的情况下,所以是这样的:

Scenario: Create a new order 
    Given I have gone to the URL 
    When I enter the NRIC/FIN: <NRIC/FIN> 
    And I choose the first available Handset Colour 
    And I enter <Full Name> as Name 
    Then my new order should be confirmed (or whatever) 

但是,如果你创建仅仅为了设置场景来测试别的东西,那么你可以欺骗和刚刚指出的顺序应该存在:

Scenario: Check the status of an order 
    Given that I have created an order: 
     | NRIC/FIN | Colour | Full Name | 
     | xxxxx | Red | John Doe | 
    When I check the status of my order 
    Then I should see a new order... 

它是由自动化是否点击在屏幕中创造秩序或只是将其插入到数据库中,所有重要的是,到时候你到命令应该存在的时候。

在一个理想的BDD世界中,小黄瓜会在实现之前写出来,但它往往不会这样工作。我仍然觉得尝试假装我在那个理想世界中编写功能是有用的。问:“在我们开始开发之前,我会怎样写这个?”可以帮助从实施细节中分离实际需求(我可以输入订单)(在输入每项数据后,我点击下一步)。