简体   繁体   中英

How can I make an ASP.NET MVC site as unit testable as an ASP.NET Web Forms site?

还有,今天是什么日子,为什么我的头像是丑陋的独角兽;-)

First, you have to use sealed classes and singletons everywhere -- none of these wrapper classes with virtual methods that can be mocked out or anything. Next, and this is important, you have to use Reponse.Write instead of returning views. It also helps to serialize the contents of all of the form parameters, encrypt them, and store them in a hidden input on the page -- then always check the new parameters against the old ones to see which things changed. Using this way you can generate these things called "events" -- they're just like button clicks and selects on Windows Forms. These are much easier to understand and simulate in your unit tests.

You have a unicorn because today is April Fools Day and Jeff is a sucker for that kind of thing.

Some would say an MVC site is more testable than a ASP.NET Forms one. You make it testable by adding tests I guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM