Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cucumber 测试是否有空字段的最佳实践_Cucumber - Fatal编程技术网

Cucumber 测试是否有空字段的最佳实践

Cucumber 测试是否有空字段的最佳实践,cucumber,Cucumber,我有一个有7个输入字段的表单 场景是,我想测试是否有字段丢失,系统应该为丢失的字段提示一个错误 因此,我制作了以下功能: Scenario: Sending request with an empty form Then I fill in "Phone" with "979000000" And I fill in "Name" with "John" And I fill in "Email" with "john@mail.me" And I fill

我有一个有7个输入字段的表单

场景是,我想测试是否有字段丢失,系统应该为丢失的字段提示一个错误

因此,我制作了以下功能:

  Scenario: Sending request with an empty form
    Then I fill in "Phone" with "979000000"
    And I fill in "Name" with "John"
    And I fill in "Email" with "john@mail.me"
    And I fill in "Circumstance" with "Trash outside"
    And I fill in "Address" with "700 University Dr. E"
    And I fill in "Start Date" with "10/31/2014"
    And I fill in "End Date" with "11/01/2014"
    When I press "Submit request"
    Then I should see prompt for all missing fields
然后逐个删除一个字段并创建一个新场景


这显然不是一个好的做法。有什么好方法可以测试所有字段吗?

我认为您可以使用场景大纲只制作“一个”场景


然后,您可以添加带有几个空字段的示例,并检查几个值为“missing”的字段。

Cucumber不是进行详尽测试的工具

如果您想测试您的模型是否验证了每个字段的预测,请使用单元测试。这将更快地运行,更容易实现

如果您想显示提示您填写空字段的机制正在工作,请仅对一个字段执行此操作(由于单元测试,您知道它对其他字段有效)

写一个特性,比如

Scenario: Incomplete form
  When I fill in the form
  And I leave a required field empy
  Then I should see a missing field prompt
考虑这一点的一种方法是不要浪费时间测试平台代码,而是集中精力测试应用程序代码

When(/^I fill the form with datas :$/) do | table |
  datas = table.hashes.first
  datas.each do |label, value|
    if !value.empty?
      @browser.text_field(name: label).set value
    end
  end
end
Scenario: Incomplete form
  When I fill in the form
  And I leave a required field empy
  Then I should see a missing field prompt