Dot-Net
specflow:-當一個步驟的參數比另一個步驟多時,“為步驟找到不明確的步驟定義”
目前我們有這一步:
[When(@"I set the scenario price for product (.*) to (.*)")] public void WhenISetTheScenarioPriceForProductPToN(string product, string priceStr)我想添加步驟:
[When(@"I set the scenario price for product (.*) to (.*) in the (.*) zone") public void WhenISetTheScenarioPriceInZoneForProductPToN(string product, string priceStr, string zone)但是,規範流程在兩個步驟之間給出了“為步驟找到了不明確的步驟定義”錯誤。
我累了:
[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)但失敗並出現“綁定錯誤:參數計數不匹配!” 我希望它會在第二個“何時”通過 null。
第二個問題是你的 (.*)。這可以擴展為匹配“abc 區域中的 xyz”。你可以只匹配一個單詞嗎?即 (\w+)
[When(@"I set the scenario price for product (.*) to (\w+)")]這也將阻止 abc 區域中較短的正則表達式匹配。
您可以通過註釋掉較長的 When 屬性和方法並調試以查看與較短的匹配的內容來測試這一點。
此外,您始終必須擁有與參數相同數量的正則表達式,這就是為什麼組合起來不起作用的原因。
這對我不起作用,這是由於“0.99”和“。”的價格。沒有被 \w 匹配。但是,這有效:
[When(@"I set the scenario price for product (.*) to (\S+)")] public void WhenISetTheScenarioPriceForProductPToN(string product, string priceStr)因為我們的“測試值”中沒有空格。