gpt4 book ai didi

c# - Specflow - 带有数据表的场景轮廓

转载 作者:太空宇宙 更新时间:2023-11-03 21:07:12 24 4
gpt4 key购买 nike

我有一系列看起来像这样的场景:

Given these receipts:
| Amount | Date | Company |
| 1000 | 2016/10/25 | One Company |
| 1200 | 2016/10/20 | Another Company |
| 1500 | 2016/10/13 | My Company |
And delay is 15
When I calculate date of payment
Then Date of payment should be 20

Given these receipts:
| Amount | Date | Company |
| 1000 | 2016/10/25 | One Company |
| 1200 | 2016/10/20 | Another Company |
| 1500 | 2016/10/13 | My Company |
And delay is 30
When I calculate date of payment
Then Date of payment should be 15

Given these receipts:
| Amount | Date | Company |
| 1000 | 2016/10/25 | One Company |
| 1200 | 2016/10/20 | Another Company |
| 1500 | 2016/10/13 | My Company |
And delay is 45
When I calculate date of payment
Then Date of payment should be 10

所以我了解了Scenario outline我尝试为上述情况制作一张收据,但由于显而易见的原因无法放入收据:

Given these receipts: '<receipts>'
And delay is <delay>
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples:
| delay | dateOfPayment | receipts |
| 15 | 20 | | Amount | Date | Company | |
| | 1000 | 2016/10/25 | one company | |
| | .............................. | |

Given我想要相同的集合,在这种情况下,receipts对于所有 scenarios在我的 Feature我如何声明一个将在 '<receipts>' 处传递的scenario outline

也许,我应该采用不同的方法吗?

-------------------------------- 已编辑 ---------- ----------------------

也许这样的事情可行(但它没有在 Gherkin 中实现):

Given these receipts: '<receipts>'
And delay is <delay>
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples:
| delay | dateOfPayment |
| 15 | 20 |

Placeholder: '<receipts>'
| Amount | Date | Company |
| 1000 | 2016/10/25 | One Company |
| 1200 | 2016/10/20 | Another Company |
| 1500 | 2016/10/13 | My Company |

最佳答案

我有一个愚蠢的想法:假设收据没有改变,我也许可以向 Scenario Outline 提供一个带有实际 table 而不是 的 Given占位符

成功了:

Scenario Outline: payment
Given these receipts:
| Amount | Date | Company |
| 1000 | 2016/10/25 | One Company |
| 1200 | 2016/10/20 | Another Company |
| 1500 | 2016/10/13 | My Company |
And delay is '<delay>'
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples:
| delay | dateOfPayment |
| 15 | 20 |
| 30 | 10 |
| 45 | 5 |

如果您像我一样在 .Net 中使用 Specflowc# specflow 将为 生成此方法给定:

[Given(@"these receipts:")]
public void GivenTheseReceipts()
{
ScenarioContext.Current.Pending();
}

不用担心,只需添加table参数,table就会像正常情况一样作为参数传递:

[Given(@"these receipts:")]
public void GivenTheseReceipts(Table table)
{
var receipts = table.CreateSet<Receipt>(); // you can even create a set given you have defined the Receipt class
}

public class Receipt
{
public decimal Amount { get; set; }
public DateTime Date { get; set; }
public string Company { get; set; }
}

------------------------ 已编辑-------------------- ------------------

它似乎也适用于 Background:

Background: 
Given these receipts:
| Amount | Date | Company |
| 1000 | 2016/10/25 | One Company |
| 1200 | 2016/10/20 | Another Company |
| 1500 | 2016/10/13 | My Company |

Scenario Outline: payment
And delay is '<delay>'
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples:
| delay | dateOfPayment |
| 15 | 20 |
| 30 | 10 |
| 45 | 5 |

现在,这只是风格问题。

另请注意,Background 将在您的 Feature 文件中可能包含的所有其他 scenarios 之前被调用。

关于c# - Specflow - 带有数据表的场景轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40436316/

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