Unit Testing rich Views for ASP.NET MVC
If I have 开发者_如何学Ca rich AJAX-driven GUI in ASP.NET MVC, how would I unit test that effectively using a framework like NUnit?
If you're looking to test the functionality of the UI, use browser automation tools like Selenium.
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.
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.
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);
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.
精彩评论