我有一系列看起来像这样的场景:
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
的位置传递
也许,我应该采用不同的方法吗?
---------------------------------- EDITED ------------ --------------------
也许这样的事情可行(但它没有在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 |
中实现):
saveData:function(){
this.getData().then(function(response){ // you can handle getData promise here
// on success
}, function(reject){
// on failure
});
}
答案 0 :(得分:3)
我有这个愚蠢的想法:鉴于收据没有改变,我可以提供给Scenario Outline
给定实际table
而不是placeholder
它有效:
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
和Specflow
specflow在c#
工作,则Given
会为table
生成此方法:
[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; }
}
------------------------- EDITED --------------------- ----------------
似乎它也适用于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
将在您scenarios
文件中的所有其他Feature
之前被调用。
答案 1 :(得分:1)
Scenario Outline
不支持表替换。
但是,你可以使用:
| delay | dateOfPayment | rcpt1Amnt | rcpt1Date | rcpt1Cmpny | rcpt2Amnt | recpt2Date | ...
| 15 | 20 | 1000 | 2016/10/25| One Company| 1200 | 2016/10/20 | ...