views:

240

answers:

2

Hello,

I have unit tests covering my model binders. I create a ModelBindingContext and populate the ValueProviderDictionary with my test values. I feel confident that once my controller gets the model, everything is covered with testing and the right things are happening. I also feel confident that if the BindingContext is correct my model will bind correctly. What I do not feel confident on is that my View, when posted back, will populate the BindingContext properly.

I've started to write WatiN tests that fill out forms, post them back, and check the resulting View. This is okay, but seems very ... indirect. For instance a page that says "your order was saved" after clicking submit -- I would have to go at the database to see if it was saved correctly. I already have tests covering that when the model passed to my controller is x, y is saved to the database. Why am I repeating this code in a view test?

What I really want is to populate the view, hit submit, and check either (a) the BindingContext or (b) the model returned from the ModelBinder.

Is there any practices on how to do this stuff?


Just wanted to add that this would be in addition to WatiN tests. I have ~50 WatiN tests right now (with plenty more to add), and if I could do the above without WatiN it would only remove a handful of tests. I'll keep using WatiN for what it is good for, but I feel like I'm abusing it right now for those few tests.

A: 

In your case, the model binding will only fail when your views fail to follow the framework conventions. The first sign of that happening, is when your view doesn't show the expected result. The next one would probably be when your WatiN tests fail on posts.

Technically, yes, this is indirect testing, but also the most pragmatic one. How would you else verify that all views adhere to the conventions, other than observe that they work?

Thomas Eyde
+3  A: 

You could try Steve Sanderson's MvcIntegrationTest from http://blog.codeville.net/2009/06/11/integration-testing-your-aspnet-mvc-application/.

Neal