views:

70

answers:

5

If I have a rich AJAX-driven GUI in ASP.NET MVC, how would I unit test that effectively using a framework like NUnit?

+4  A: 

If you're looking to test the functionality of the UI, use browser automation tools like Selenium.

Dave Swersky
+1  A: 

With NUnit, you would primarily be testing your controller actions -- i.e., given a set of parameters and a configuration, does the method return the correct result and view model. If you need to test your client-side javascript, you should look at either a javascript unit testing framework or a UI testing tool, such as Selenium or WatiN.

tvanfosson
+1  A: 

You can use Selenium IDE to record tests and the generate NUnit testcases to verify behaviour and output of your views.

Steve Sanderson also blogged earlier on today about HtmlUnit on .NET as 'headless browser'. (Testing using the Selenium server can be slow, because it requires creating an instance of FireFox, IE etc);

Kirschstein
+2  A: 

jQuery has a unit testing project called QUnit which you could use to test your ajax code from a client. It isn't going to integrate with NUnit, but it is another option.

Redbeard 0x0A
+1  A: 

You would have to unit test your ajax calls and not your UI per se., For example if you are getting some json data through a ajax call, this would translate to a controller method which can be unit tested.

I you want to unit test something which happens after the data reaches the browser then its a whole different ball game and not related to MVC.

ravi