Has anyone used Steve Sanderson’s MvcIntegrationTe

2019-03-18 14:06发布

问题:

I was looking into additional ways to test ASP.NET MVC applications and ran into Steve Sanderson’s MvcIntegrationTestFramework. The approach looks rather promising but I was wondering if anyone had any actual experience to share.

回答1:

I'm having some really good results from it. I don't care what anyone else on here says about the need to test views, as soon as you add your first line of code to a view, even if the code is strictly presentation-related, you introduce a potential for errors for which it would be a good idea to write automated tests. My primary interest is just to catch as many white screen and yellow screen exception/errors as possible. To do so I have been using the snippet from Steven's introductory blog post to ensure that the page rendered properly without throwing any exceptions:

Assert.IsTrue(result.ResponseText.Contains("<!DOCTYPE html"));

The small pitfalls that I see with this framework might be:

  • If your web site is doing some pretty complex model binding between the views and action methods, you might find yourself creating some pretty large NameValueCollections such as in this example (an action method which actually takes a LogonModel view model object), since I don't see any way of passing any complex view model object types into your action methods by using this framework:

var result = browsingSession.ProcessRequest("/account/logon", HttpVerbs.Post, new NameValueCollection { {"UserName","myName"}, {"Password", "myPassword"}, {"returnUrl", "/home/myActionMethod"} });

  • Executing browsingSession.ProcessRequest("url") creates an application host/context which actually executes the web code that you are testing using the configuration in the project which you are testing. This means the tests run a bit slowly, and could possibly modify real data, since I don't see a quick and easy way of swapping out your data access repositories in your web project under test with fake versions by using any facility built into this test framework. In other words, you'd probably need to roll your own using some web.config-based means.


回答2:

After reading ardave's answer a while ago, we actually went to try it out for ourselves for our new Orchard based application Marinas.info.

First of all, I recommend anyone to start from a fork of this version as it's even easier to set up than the original.

For any "normal" MVC3 app it simply works. Unfortunately, together with Orchard it didn't play well, at least not with an unmodified version of their Global.asax.cs. So we still went down the browser based testing road but we keep using it to execute Orchard commands inside the app which is fast enough.



回答3:

I haven't used this framework. But based on my experience of reading his book -Pro ASP.NET MVC Framework, and another validation framework xVal he developed, I would say "HE IS GREAT".



回答4:

Experimented with it a little and it could be very useful in some situations. General thumbs up and if I saw further work on it I would use on a future project.

Didn't proceed as already have WatIn setup and taking care of some things I wouldn't like to tackle again in this framework. E.g. authentication through a dialog, which would probably require a code change.