Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

UITestBench, a lightweight UI testing library

, 3 Apr 2008
This article describes how to build a lightweight test bench for testing user interfaces which are written entirely in C#/.NET, using NUnit or any other unit test framework.
UITestBench.zip
UITestBench
UITestBench
bin
Debug
UITestFramework.dll
Framework
Properties
UITestDemoApp
bin
Debug
UITestDemoApp.exe
UITestDemoApp.vshost.exe
Properties
Settings.settings
UITestDemoApp_UITest
bin
Debug
nunit.framework.dll
UITestDemoApp.exe
UITestDemoApp_UITest.dll
UITestFramework.dll
Import
nunit.framework.dll
Properties
Settings.settings
/*
 * This file is licensed under the Code Project CPOL License
 * http://www.codeproject.com/info/cpol10.aspx
 * 
 * © Steffen Schütte 2008
 */

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using de.steffenschuette.UITest.Framework;
using System.Threading;
using System.Windows.Forms;



namespace de.steffenschuette.UITest.DemoApp.UITest
{
    [TestFixture]
    public class TestFixture1
    {
        private UITestBench myTestBench;

        [SetUp]
        public void SetUp()
        {
            Console.WriteLine("Setup ThreadId: " + Thread.CurrentThread.ManagedThreadId);

            myTestBench = new UITestBench();
            myTestBench.StartApplication("UITestDemoApp", null);

            //Some some to start the demo app
            Thread.Sleep(2000);
        }

        [TearDown]
        public void TearDown()
        {
            myTestBench.TerminateApplication();
        }

        [Test(Description="TestCase 1")]
        public void TestCase1()
        {
            Console.WriteLine("TC1 ThreadId: " + Thread.CurrentThread.ManagedThreadId);

            myTestBench.PerformClick("Form1", "File/Open text file 1...");
            SendKeys.SendWait("file1.txt");
            SendKeys.SendWait("{ENTER}");
            Thread.Sleep(2000);

            myTestBench.PerformClick("Form1", "File/Open text file 2...");
            SendKeys.SendWait("file2.txt");
            SendKeys.SendWait("{ENTER}");
            Thread.Sleep(2000);

            myTestBench.PerformClick("Form1", "toolStrip1/Merge");
            Thread.Sleep(2000);

            myTestBench.SetText("MergeDlg", "MergeDlg/Demo Textbox", "Text has been set");
            Thread.Sleep(2000);

            myTestBench.PerformClick("MergeDlg", "MergeDlg/MixFilesBtn");
            Thread.Sleep(4000);

            myTestBench.SetSelectedIndex("MergeDlg", "MergeDlg/ListBox[2]", 1);

            Thread.Sleep(4000);

           
            myTestBench.PerformClick("MergeDlg", "MergeDlg/OK");
            Thread.Sleep(2000);

            myTestBench.PerformClick("Form1", "File/Exit");
        }

        [Test(Description = "TestCase 2")]
        public void TestCase2()
        {
            Console.WriteLine("TC2: ThreadId" + Thread.CurrentThread.ManagedThreadId);

            myTestBench.PerformClick("Form1", "File/Open text file 1...");
            SendKeys.SendWait("file1.txt");
            SendKeys.SendWait("{ENTER}");
            Thread.Sleep(2000);

            myTestBench.PerformClick("Form1", "toolStrip1/Merge");
            Thread.Sleep(2000);
            myTestBench.PerformClick("MergeDlg", "MergeDlg/MixFilesBtn");
            Thread.Sleep(2000);

            //No more testing as this use case forced an error in the aplication under test
            //to show that this does not crash the unit test
        }

     
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

slkr171
Software Developer
Germany Germany
I currently hold the following qualifications
 
- PhD in Computer Science
- M.Sc. in Software Technology
- Diplom (FH) in Computer Science

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 3 Apr 2008
Article Copyright 2008 by slkr171
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid