How to test Asp.Net ControlDesigners without VisualStudio? (PROTOTYPE)
I was recently tasked to prototype a way to test our ControlDesigners without using VisualStudio. For those of you that are not familiar with ControlDesigners here is an overview. In short, ControlDesigners is what give an Asp.Net runtime control a design time experience when hosted inside VisualStudio. Traditionally, our team (and most teams in DevDiv) prefer to automate all of VisualStudio to get regression coverage of designer features.
Now, ControlDesigners that were written for Asp.Net 1.0 and 2.0 do not have unit tests (yeah, our team didn't see the light until later), so our QA team has had to maintain a big automation bed to verify regressions in our ControlDesigners that is generally a pain to write (constant product and framework changes, coupled with the fact that the Visual Web Developer team rewrote the design surface twice make VisualStudio UI testing very challenging). So one approach that we are investigating is to see if we can add unit tests for our old ControlDesigners.
You can download a simple prototype of how such testing may look like HERE.
This is very early, but it gave us good confidence that we could probably test most of our core controls. Here is an example of how a very simple test looks like:
1: [TestMethod]
2: public void VerifyRenderingWithId()
3: {
4: TestDesigner designer = new TestDesigner();
5: HyperLink control = new HyperLink();
6: control.ID = "HyperLink1";
7:
8: designer.VerifyRendering(@"<a id=""HyperLink1"" Href=""url"">[HyperLink1]</a>", control);
9: }
There is also a more advanced test to verify the design time rendering of a GridView control that is bound to a DataSource control:
1: [TestMethod]
2: public void VerifyRenderingWithSchema()
3: {
4: TestDesigner designer = new TestDesigner();
5:
6: TestDataSourceViewSchema schema = new TestDataSourceViewSchema();
7: schema.AddField(new TestDataSourceFieldSchema());
8: schema.AddField(new TestDataSourceFieldSchema());
9: designer.AddDataSourceControl("DataSource1", schema);
10:
11: GridView control = new GridView();
12: control.ID = "GridView1";
13:
14: ControlDesigner controlDesigner = designer.AddDataBoundControl(control, "DataSource1");
15:
16: string expectedHtml = @"<table cellspacing=""0"" rules=""all"" border=""1"" id=""GridView1"" style=""border-collapse:collapse;"">
17: ...
18: cut for space
19: ...
20: ";
21: designer.VerifyRendering(expectedHtml, controlDesigner);
22: }
Some comments regarding this project:
-
The idea is that most ControlDesigners make calls into our runtime controls, which makes the designer vulnerable to changes to our runtime code. Having this level of simple regression tests can help us catch changes that could break the design time experience of controls.
-
Notice that I am making simple string comparisons to verify big chunks of HTML code. Internally, we use a TagDiffer tool that helps in abstracting common rendering changes that should not break the test (like attribute ordering). I had to modify the project to not include these binaries since I am not sure that I am allowed to release it.
-
I did a little bit of research to see if I could find a mock implementation of the designer that would help me with this. I could not find anything, but if anybody knows of a tool that we can use or has some pointers of something similar I would really appreciate it.
-
There are many services that are not implemented, so plugging other controls into this may or may not work :P
Any feedback you have is welcome.
Federico Silva Armas
SDET ASP.NET QA Team