Unit Testing of ASP.NET Code

I read about MVC, in which authors believe that testability is one of the main strengths of MVC. They go to compare this with ASP.NET WebForms and how hard it is to test the code in WebForms.

I understand that this is difficult, but can anyone explain how unit tests were written to test code for logic in the old days?

+6
unit-testing tdd
source share
2 answers

In the old days, I tested aspnet web forms using the Model View Presenter template. I was able to test the code using this template because I abstracted the conditional logic / loops / etc into a separate class that did not live inside the webforms framework.

What remained in the webforms codebehind code was nothing more than a few properties and a page load call to run the presenter class itself.

Then, each event handler simply passes the work on to the presenter class.

I spent a lot of time on this template and found that it makes things more convenient for testing, but this is a lot of work compared to aspnet mvc

+5
source share

The code behind is the simple methods in the class (the only difference with the other class is that this class inherits from the Page object)

Thus, this can be verified. most problems arise because methods are closely related to web.ui controls, such as the grid; it wasn’t so easy to fake. If you didn't fake the user interface controls, you also tested the internal operation of the user interface controls, which went a bit too far.

+3
source share

All Articles