1

新しいプロジェクトでは、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値をコミットするロジックがあり、受け入れテストに合格するようにします。

私の質問はこれとほとんど同じです。specflow機能はasp.netwebformsプロジェクトの単体テストにどのようにリンクしますか?

SpecFlow、NUnit、MVCを使用して同様の作業を行ったことがある場合は、ご意見をお聞かせください。。

4

0 に答える 0