Specflow/Gherkin: 如何处理坏数据
Specflow/Gherkin: How to handle bad data
我是 Specflow 的新手,所以开始吧;
对于我下面的例子,我是否应该测试坏的?如果我这样做 table 将不会让您添加错误的值。所以代码会出错,因为它以错误的类型出现。我想我只需要知道其他人如何处理验证用户不能输入错误数据? (由于机密信息,字段名称已更改)
要求说:
验证用户不能将比率设置为负数或大于1。比率范围是从0.9999到0。
确认用户输入的汇率不能超过 4 位小数。
Given the lc does not exist
| Lc |
| Test90 |
| Test00 |
When I add a Lc
| Lc | Somekind of ID| Rate |
| Test90 | 2 | 0.9999 |
| Test00 | 4 | 0 |
Then the lc should be defined
| Lc |
| Test90 |
| Test00 |
您在整个测试过程中测试了 2 个值,这有点奇怪。
我很想像这样重写:
Scenario Outline: valid lc's can be created
Given the lc named <lc> does not exist
When I add a Lc named <lc> with Id <id> and rate <rate>
Then the lc named <lc> should be defined
Examples:
| Lc | Id | Rate |
| Test90 | 2 | 0.9999 |
| Test00 | 4 | 0 |
Scenario Outline: Invalid lc's cannot be created
Given the lc named <Lc> does not exist
When I add a Lc named <Lc> with Id <Id> and rate <Rate>
Then the lc named <Lc> should not be defined
And an error should have been raised saying the rate was invalid
Examples:
| Lc | ID | Rate |
| Test90 | 2 | 1.999 |
| Test90 | 2 | 0.99999 |
| Test90 | 2 | -0.9 |
| Test00Y | 4 | 6 |
| Test00Y | 4 | |
And an error should have been raised saying the rate was invalid
这一步显然是可选的,但表明由于费率无效,这预计会失败。
我是 Specflow 的新手,所以开始吧;
对于我下面的例子,我是否应该测试坏的?如果我这样做 table 将不会让您添加错误的值。所以代码会出错,因为它以错误的类型出现。我想我只需要知道其他人如何处理验证用户不能输入错误数据? (由于机密信息,字段名称已更改) 要求说:
验证用户不能将比率设置为负数或大于1。比率范围是从0.9999到0。
确认用户输入的汇率不能超过 4 位小数。
Given the lc does not exist
| Lc |
| Test90 |
| Test00 |
When I add a Lc
| Lc | Somekind of ID| Rate |
| Test90 | 2 | 0.9999 |
| Test00 | 4 | 0 |
Then the lc should be defined
| Lc |
| Test90 |
| Test00 |
您在整个测试过程中测试了 2 个值,这有点奇怪。
我很想像这样重写:
Scenario Outline: valid lc's can be created
Given the lc named <lc> does not exist
When I add a Lc named <lc> with Id <id> and rate <rate>
Then the lc named <lc> should be defined
Examples:
| Lc | Id | Rate |
| Test90 | 2 | 0.9999 |
| Test00 | 4 | 0 |
Scenario Outline: Invalid lc's cannot be created
Given the lc named <Lc> does not exist
When I add a Lc named <Lc> with Id <Id> and rate <Rate>
Then the lc named <Lc> should not be defined
And an error should have been raised saying the rate was invalid
Examples:
| Lc | ID | Rate |
| Test90 | 2 | 1.999 |
| Test90 | 2 | 0.99999 |
| Test90 | 2 | -0.9 |
| Test00Y | 4 | 6 |
| Test00Y | 4 | |
And an error should have been raised saying the rate was invalid
这一步显然是可选的,但表明由于费率无效,这预计会失败。