Here's a question from a reader who's working with the code that James McCaffrey (also known as Dr. James McCaffrey in our article archives) provided in his article Build Quick and Easy UI Test Automation Suites with Visual Studio .NET from the January 2003 issue of MSDN Magazine.

I have attempted to go through this tutorial. It seems that several errors have occurred. I have also noticed that the downloadable solution example is using an AssemblyInfo.cs. There is no mention of this anywhere in the tutorial. I am using Visual Studio 2005. See attached for my solution .cs files. I am having a hard time finding out what I am missing. Any assistance is much appreciated.

Error 1  The type or namespace name 'Assembly' could not be found (are you missing a using directive or an assembly reference?)

Error 2  'MyWinAppTester.Program.testAssembly': cannot declare instance members in a static class           

Error 3  'MyWinAppTester.Program.testForm': cannot declare instance members in a static class  ...

Evan

Hi Evan,

The main issue is that I wrote the article “Build Quick and Easy UI Test Automation Suites with Visual Studio .NET” for Visual Studio 2003.  The code still works but you need to make a couple of minor adjustments; the culprit is the VS 2005 partial class mechanism.

First, follow the steps to create the MyWinApp application just as described in the article.  Make sure you get it to work.

Next, create the MyWinAppTester application.  Add the three button controls and the two text box controls as described.  Add the two using statements as described.  But when the article states, “Add the code shown in Figure 3 to your project just below the Main method.” you must paste the code in Fig. 3 directly below the existing

public Form1()
{
    InitializeComponent();
}

In file Form1.cs – not below Main() in file Program.cs.  This is a consequence of the partial class “feature” in VS 2005 that can be really annoying at times.  Additionally watch the

EventHandler eh = (EventHandler)Delegate.CreateDelegate(typeof (EventHandler), form, methodName);

It should all be on one line (it was cut for formatting).

After that, follow the article and paste the code in Fig. 4 into the two button handlers as described.  The test automation should now be ready to build and run.

Hope this helps.

James M