开发者

SpecFlow and BDD in ASP.NET MVC Application

I am writing some BDD style Spec Flow test which is working out smoothly! Now, I am in a position to test that the data annotations validations are fired. I am thinking that this test should be performed by using WatiN tool since the UpdateModel is fired when the values from开发者_JAVA百科 the form are posted.

How do you test that the validations are firing?


There are a number of ways you can do this. You dont have to use WatiN to check validations, I am using SpecFlow to call controller methods and then interrogate the ModelState property checking for the errors I expected to be raised from the invalid data I entered.

You can also use WatiN to check that particular error text is displayed on screen by attatching to the browser and using the Find.ByText("Error Message") method.

If you haven't already I strongly suggest having a read of this article, helped me alot when starting out with SpecFlow/WatiN and BDD: http://msdn.microsoft.com/en-us/magazine/gg490346.aspx

Hope that helps.


By testing them with invalid data...(and valid data)

If your model has an annotate just fire values at it you may write a scenario like

Scenario: Adding an invalid user   
GIVEN I am in the add user page  
AND I have not filled in the  name   
WHEN I Add  
THEN I should see the error defined in my annotation

more on testing annotations is here http://bradwilson.typepad.com/blog/2009/04/dataannotations-and-aspnet-mvc.html but you just want them to fire. Remember you are testing from the outside in this case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜