specflow看起来像是我希望我的团队考虑使用的解决方案。然而,我的经理并不真正喜欢BDD风格的测试。由于specflow与visual studio的良好集成,我想知道我是否可以利用specflow框架,同时允许更少bdd风格的测试形式。
例如,不要像以下那样编写测试:
Scenario: Help->About
Given a user is logged in to "http://..." as "user/password"
And they are on the page titled "Home"
When I click on "about"
Then I should see a window titled "about"
...我想把它写成:
Scenario: Help->About
log in to "http://..." as "user/password"
click on the "About" link
assert "About" window should be visible
换句话说,必须我使用Given
,Then
等关键字,或者是否能够处理不以这些词开头的步骤?< / p>
答案 0 :(得分:1)
Specflow使用代码生成器中的Given,When和Then关键字生成如下测试用例:
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("See the content of a message")]
public virtual void SeeTheContentOfAMessage()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Help->About", ((string[])(null)));
this.ScenarioSetup(scenarioInfo);
testRunner.Given("a user is logged in to \"http://\" as user/password");
testRunner.When("I click on About");
testRunner.Then("I should see a window titled about");
testRunner.CollectScenarioErrors();
}
将测试更改为您描述的方式的唯一方法是更改代码生成器。 GherkinDialect中的TryParseStepKeyword()
方法是一个良好的开端