« How to: Move the mouse pointer programmatically | Main | Microsoft News - Bad Shapes. »
August 19, 2005
Visual Studio Team System - Magic Tests
I've been playing around with the unit testing in VSTS and I really like what I see. For example, it fully supports building tests that will drive the user interface of a Windows Forms application by calling the various Form event handlers.
For example, if you have a Button1_Click in a form, you can generate a test for it that looks like:
[TestMethod()]
public void button1_ClickTest()
{
Form1 target = new Form1();
TestProject1.WindowsApplication1_Form1Accessor accessor =
new TestProject1.WindowsApplication1_Form1Accessor(target);
object sender = null; // TODO: Initialize to an appropriate value
EventArgs e = null; // TODO: Initialize to an appropriate value
accessor.button1_Click(sender, e);
Assert.AreEqual(accessor.label1.Text,"This is a test");
}
Look at what's going on here. The test doesn't call into Form1 directly. It wouldn't be able to, as button1_Click is private. Instead, it creates an instance of a proxy class called "accessor". This is some code-generated goo that uses reflection to get at the private members of the form. This also lets you do stuff like "accessor.label1.Text", which is also private. This part is ½ magic.
The full FM is this; the windows form application that I'm testing compiles to an EXE, not a DLL. How is my unit test (which is in a separate assembly) able to call into a function that's inside of an EXE? And, does this open the door to something similar to OLE automation of applications? Inquiring minds want to know.
Posted on August 19, 2005 at 11:55 AM | Permalink
Comments
The comments to this entry are closed.