简体   繁体   中英

Unit test Web Forms in Visual Studio 2012

I can't seem to find a walkthough/tutorial/blog posts etc on how to Unit test Web Forms in Visual Studio 2012 . MSDN doesn't seem to cover it. The only thing I've been able to gleam from surfing for walkthrough's is that I need to have a clear separation of concerns to appropriately test an aspx.cs file. What am I missing? Are there any solid recent walkthrough's on how to implement simple unit testing in a Web Forms project?

Unit testing your code behind is practically impossible, since there's no context, no request and mocking all that is very difficult.

what you should do instead is separate your logic into another library and unit test that library. This would leave only view specific code in your code behind.

That code can then be tested through UI tests (with a tool like Selenium for example)

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