How do you unit test Server Controls? RRS feed

  • Question

  • User907266268 posted

    I have been doing some research and thinking around server control testing.  We are moving towards building a set of controls that can be used by non-developers to compose our web sites.  We stated out building pages, later we transitioned to user controls to focus on individual elements.  Now we're moving towards server controls to simplify the deployment process and allow the composition of the site and functionality by dragging from the toolbox.  The resulting bits will give us a framework of context aware, strongly typed form, list, and data controls.  As we make this we want to maintain and improve the level of unit testing we are doing.  When I think of unit tests for server controls I'm most concerned with factors that affect rendering, data binding, and post-back. This leaves me with a few objectives:

    • Ensure controls are rendered properly in the browser and follow XHTML 1.1 Strict rules (we aim to support N - 1 major browser versions)
    • Validation on individual fields is functioning
    • Client-side script (including callbacks) execute properly
    • Control user stories are functioning as expected at the UI layer

    My question is how do you approach this with your server controls?  My first thoughts would be to dynamically build a page on the fly similar to setting up a unit test, serve it up through WebDev.WebServer.exe, and poke at it with a framework like WebAii or WaitN.  What I have seen to date focuses on test harnesses using pre-built pages or web applications at the page level, not the control level.

    Sunday, March 23, 2008 2:14 PM


  • User-16411453 posted

    I've been doing the same thing for my program, in which all major components are now controls that can be dragged onto the page via toolbox in designer.  Now the end user has complete control of the program, and can alter the page anyway they choose.  Also now the code is unified, and allows for precise code updates, without altering the page the end user created.

    We test the controls manually in the browsers.  So far, we have had only a couple of controls not function right, and have fixed them to the best of out abilities.  We usually test the controls by checking the source code, to see if they match up correctly. Take the original page output, and compare it against the page output with the control.

    If you create the controls dynamically, they will automatically format to the proper format, xhtml, html 4 , etc

    We build the validation into the control, using the Required Validators, quite difficult though, but you get the hang of it.

    There's a company in India that says they'll do it for us, and provide complete reports. I think I'm going to take them up on it. 


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 23, 2008 4:32 PM