Home

Code Corner

Bookshelf

Websites

Hire Kenny

Code Corner - Tools - Test Studio

This is an ongoing project so check back often.

 

Test Studio .NET: Putting .NET to the Test (4 Nov 2001)

Writing Your Own Tests (6 Nov 2001)

 

Test Studio .NET: Putting .NET to the Test (4 Nov 2001)

Test Studio is a desktop application I am writing to see just how much I can do with .NET. An important requirement is that Test Studio must be a realistic application, not some tool you whip up over the weekend with the Forms Designer. As it doesn't pay the bills I work on Test Studio in my spare time. So check back every now and then to see how its coming along. I sure wish it would pay the bills as its a lot of fun!

Test Studio is an extensible software-testing framework. How many times have you wanted to test some component or piece of code you were working on only to spend more time writing (typically) buggy threading code to hammer the life out of your components? Test Studio provides a reliable environment in which you can stress test your own projects.

Even if you’re not too interested in testing software (but you should be!) this program touches on many aspects of .NET programming with a bias towards Windows Forms based programming. With all the talk about Web Services and ASP.NET it is easy to forget that Windows Forms will completely change the way software developers write desktop applications.

Although you can automate tests to run them as part of a batch process, you would typically use the Test Studio Explorer to manage and run tests. 

As you can see there's quite a bit to Test Studio. I plan on writing an article for MSDN Magazine when I'm done. Should be an interesting read.  :)   Test Studio has been a useful exercise for me because it has exposed me to many areas of .NET. For example I've gained experience in designing a good user interface using System.Windows.Forms. When I am done with Test Studio I will release the source code. What you will find is a loosely coupled, event driven design. No long lists of message maps and interdependencies that you find in typical MFC applications (not to say that you can't write elegant applications in MFC). It has also taught me about how to manage threads effectively using the .NET Framework and how cool reflection is! 

To add a test to a project you simply use the Add Test Wizard.

Assuming the animation is working OK you should be able to see how you walk through adding a script test. The wizard is an example of a common Windows paradigm that isn't explicitly supported by the .NET Framework but is easily implemented using the building blocks provided.

Well that's enough for today. Check back again soon for more information about Test Studio .NET!

 

Writing Your Own Tests (6 Nov 2001)

Writing tests for Test Studio is easy. You start by implementing two interfaces, ITest and ITestDefinition. A standard implementation of ITestDefinition, called TestDefinitionBase, is even provided to make it even easier. ITest is defined as follows:

namespace Kerr.TestStudio.ObjectModel
{
    /// <summary>
    /// Provides functionality to execute and manage a test. Test plug-ins will
    /// implement this interface to implement their test-specific code.
    /// </summary>
    public interface ITest
    {
        /// <summary>
        /// Runs the actual test.
        /// </summary>
        bool Run();

        /// <summary>
        /// Allows a test object to perform whatever cleanup is necessary
        /// before it is destroyed.
        /// </summary>
        void Shutdown();
    }
}

The ITest interface implies a constructor that takes a TestContext and ITestDefinition as parameters. So a simple test could be implemented like this:

using System;
using Kerr.TestStudio.ObjectModel;

public class Test : ITest
{
    #region ITest Implementation

    public Test(TestContext context,
                    ITestDefinition definition)
    {
        m_context = context;

        m_context.Trace("Starting");
    }

    public bool Run()
    {
        m_context.Trace("Running");
        return true;
    }

    public void Shutdown()
    {
        m_context.Trace("Stopping");
    }

    #endregion

    #region Data Members

    private TestContext m_context;

    #endregion
}

When you add your test to a project in Test Studio Explorer, you have the option to specify how many instances of your test to run as well as how many iterations of the test to execute for each instance. For each instance you specify, Test Studio will create one instance of your ITest derived class and will call the test's Run method once for every iteration. 

As you can see there isn't much to the test class. It is intentionally simple so that you can focus on your test-specific code.

 

kennykerr@hotmail.com