我们正在尝试将BDD和TDD方法结合到我们的新项目中。
在我们的MVC3项目中使用Specflow,NUnit和WatiN,我试图遵循Outside-in过程的逻辑。 http://msdn.microsoft.com/en-us/magazine/gg490346.aspx 我想知道我要做的是正确的。
Feature: Commit RPI, As any user, I want to commit all RPI values
Scenario: Commit RPI values, Given I am in the RPI screen And I have entered RPI values
| Year | Month | RPI Value |
| 2012 | 1 | 1.2 |
当我想提交RPI值时,应提交RPI值
验收测试如下:
[Given(@"I am in the RPI screen")]
public void GivenIAmInTheRPIScreen()
{
WebBrowser.Current.GoTo("http://localhost:8010/"); //WebBrowser is the instance of Internet Explorer created by WatiN
Assert.AreEqual(WebBrowser.Current.Title, "RPI List");
}
***This step will initially fail as there will not be any RPI List screen. So, I’ll go to the web project, create a controller and view. When I run the test again, WatiN will be able to open up the screen and pass the test.***
[Given(@"I have entered RPI values")]
public void GivenIHaveEnteredRPIValues(Table tblRPI)
{
if (tblRPI.Rows.Count > 0)
{
var txtYear = (TextField) WebBrowser.Current.Elements.First(Find.ById("txtRPIYear"));
if (txtYear != null)
txtYear.Value = tblRPI.Rows[0]["Year"];
var txtMonth = (TextField)WebBrowser.Current.Elements.First(Find.ById("txtRPIMonth"));
if (txtMonth != null)
txtMonth.Value = tblRPI.Rows[0]["Month"];
var txtValue = (TextField)WebBrowser.Current.Elements.First(Find.ById("txtRPIValue"));
if (txtValue != null)
txtValue.Value = tblRPI.Rows[0]["RPI Value"];
}
else
{
Assert.True(false);
}
}
[When(@"I want to commit RPI values")]
public void WhenIWantToCommitRPIValues()
{
var btnCommitValues = (Button)WebBrowser.Current.Elements.First(Find.ById("btnCommitValues"));
if (btnCommitValues != null)
{
btnCommitValues.Focus();
}
else
{
Assert.IsTrue(btnCommitValues != null);
}
}
[Then(@"RPI values should be committed")]
public void ThenRPIValuesShouldBeCommitted()
{
var btnCommitValues = (Button)WebBrowser.Current.Elements.First(Find.ById("btnCommitValues"));
if (btnCommitValues != null)
{
btnCommitValues.Click();
}
else
{
Assert.IsTrue(btnCommitValues != null);
}
}
此步骤将失败,因为没有任何提交值的逻辑。在这个阶段,我将停止BDD并继续为提交逻辑编写单元测试用例。我将使用NUnit编写各种测试用例,让它们通过,这样当我回到acceptanace测试时,将会有一个提交RPI值的逻辑,这些值将通过我的单元测试并且接受测试现在将通过。
我的问题与此How do specflow features link to unit tests in asp.net webforms projects?
几乎相似如果您使用SpecFlow,NUnit和MVC完成了类似的工作,请与您分享您的想法。