gpt4 book ai didi

automated-tests - 如何编写具有需要大量输入和大量输出的功能的 Gherkin 测试?

转载 作者:行者123 更新时间:2023-12-03 09:03:22 25 4
gpt4 key购买 nike

我对小 cucumber 还很陌生,正在为我的第一个项目而苦苦挣扎。基本上,我们有很多输入参数,这些参数是一个精美的计算器所需要的,可以帮助人们确定他们是否能够负担抵押贷款。

我最好是专注于输出的一部分并仅指定该输入所需的输入,还是将每个输入列为单独的给定/与?例如

Scenario: Calculate loan amount and LVR
Given the user is on the purchase calculator page
And has filled in the rest of the calculator fields
And entered $450,000 as their purchase price
And entered $100,000 as their savings
When the user submits the calculator
Then the calculator will display the loan amount of $350,000
And an LVR of 77.78%

或者

Scenario: calculate Homeloan affordability
Given the user is on the Calculator page
And the user has entered 21 Fake Street as the purchase property
And the user entered $450,000 as their purchase price
And the user entered $100,000 as their savings
And the user has selected that there are two applicants
And the user has selected two dependants
And the user has entered $1000 monthly expences
And...
And...
When the user clicks Calculate
Then the calculator will display the loan amount of $350,000
And an LVR of 77.78%
And a predicted interest rate of 4.3%
And display a google street view image of the property they have selected
And...
And...

第一个更有意义,更容易阅读,并且测试了功能的一个特定部分,所以它看起来是理所当然的。但是我该如何编写它并涵盖填写“并已填写计算器字段的其余部分”的所有必需(但对于此测试并不重要)信息?

我是否遗漏了一些明显的东西?

最佳答案

不幸的是,我不得不不同意之前的回应。使用 Gherkin 的最佳方法是通过示例。我们应该明确,而不是含蓄。有一些关于这个主题的很棒的书,包括《Specification by Examples》和《Writing Great Specifics》,它们对它的解释比我在这里更好。这是我的写法:

Scenario: Calculate loan amount and Loan to Value Ratio
Given the user has filled in the purchase calculator information
| Purchase Price | Savings |
| $450,00 | $100,000 |
When the user submits the calculator
Then the calculator will display the loan details
| Total Loan | LVR |
| $350,000 | 77.78% |

更好的是,您可以使用场景大纲

Scenario Outline: Calculate loan amount and Loan to Value Ratio
Given the user has filled in the <purchase-price> and <savings> calculator information
When the user submits the calculator
Then the calculator will display the <total-loan> and <lvr>
And the message bar will display <message>

Examples:
| Purchase Price | Savings | Total Loan | LVR | Message |
| $450,000 | $100,000 | $350,000 | 77.78% | OK |
| $500,000 | $0 | $500,000 | 100% | OK |
| $100,000 | $50,000 | $50,000 | 50% | OK |
| $100,000 | $49,999 | $0 | 0% | Insufficient savings |

注意示例如何包含

  1. 阳光灿烂的日子场景
  2. 边界条件
  3. 错误情况

您甚至可以有多组示例。您可以有一组像上面这样的示例,重点关注最低接受标准——获得非常繁忙的产品负责人批准所需的最低标准。然后,您可以在单独的示例集中包含额外的示例以进行彻底的测试。有很多可能性。

回答您的第二个问题 - 您是否始终在示例表中包含所有数据字段?答案是不。您包含重要的数据字段。必须包含实际影响答案的数据字段。应删除额外的数据。您还可以进行总结 - 例如,如果贷款申请人的位置很重要,请考虑仅使用邮政编码,而不是包含完整地址。您仍然可以在代码中获得完整的地址。

如果数据很重要,而且非常冗长,那么我会执行以下操作:将测试用例分割为几类。对于每个类别,只有少数数据字段会发生变化,其余部分保持不变。将恒定的内容放在场景上方的“背景”部分中。如果您仔细命名类别,即使对于非常复杂/大型的数据字段集,这也具有很好的可读性和可维护性。

这个网站很好地记录了 Gherkin:http://docs.behat.org/en/v2.5/guides/1.gherkin.html

关于automated-tests - 如何编写具有需要大量输入和大量输出的功能的 Gherkin 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48738205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com