Ian*_*ose 9 .net unit-testing specflow
目前我们有这个步骤:
[When(@"I set the scenario price for product (.*) to (.*)")]
public void WhenISetTheScenarioPriceForProductPToN(string product, string priceStr)
Run Code Online (Sandbox Code Playgroud)
我想补充一步:
[When(@"I set the scenario price for product (.*) to (.*) in the (.*) zone")
public void WhenISetTheScenarioPriceInZoneForProductPToN(string product, string priceStr, string zone)
Run Code Online (Sandbox Code Playgroud)
然而,规范流程给出了两个步骤之间的"步骤中找到的模糊步骤定义"错误.
我累了:
[When(@"I set the scenario price for product (.*) to (.*) in the (.*) zone")]
[When(@"I set the scenario price for product (.*) to (.*)")]
public void WhenISetTheScenarioPriceInZoneForProductPToN(string product, string priceStr, string zone)
Run Code Online (Sandbox Code Playgroud)
但失败的是"绑定错误:参数计数不匹配!" 我希望它会在第二次"当"时传递null.
AlS*_*Ski 11
问题是你的(.*).这可以扩展到匹配"abc区域中的xyz".你可以只匹配一个单词吗?即(\ w +)
[When(@"I set the scenario price for product (.*) to (\w+)")]
Run Code Online (Sandbox Code Playgroud)
这样就可以防止abc区域中较短的正则表达式匹配.
您可以通过注释掉较长的属性和方法以及调试来查看与较短的匹配项来测试这一点.
此外,您始终必须具有相同数量的正则表达式作为参数,这就是组合的一个不起作用的原因.
这对我不起作用,这是由于"0.99"和"."的价格.没有被\ w匹配.但是这有效:
[When(@"I set the scenario price for product (.*) to (\S+)")]
public void WhenISetTheScenarioPriceForProductPToN(string product, string priceStr)
Run Code Online (Sandbox Code Playgroud)
因为我们的"测试值"没有空格.
| 归档时间: |
|
| 查看次数: |
5076 次 |
| 最近记录: |