Click here to Skip to main content
14,634,723 members
Articles » Platforms, Frameworks & Libraries » .NET Framework » General
Article
Posted 29 Jul 2020

Tagged as

Stats

4K views
153 downloads
9 bookmarked

Generic Testing Framework

Rate this:
4.25 (5 votes)
Please Sign up or sign in to vote.
4.25 (5 votes)
30 Jul 2020CPOL
Generic framework to “programming” of any test cases in dynamic way
In this post, you will see a very generic framework to “programming” test cases in dynamic way which enables execution of “testing bricks” in a defined order.

Introduction

This tool is a very generic framework to “programming” of any test cases in dynamic way, a dynamic “final state machine” that enables the execution of any “testing bricks” in a defined order.

Each "brick" is largely configurable in its parameters, the output of one "brick" can be redirected to the input of any other "brick". You can reference the output of the previous "bricks" by selecting the number of it in the combobox of the column "InputRow".

The order of the "bricks" can be changed easily by adding / deleting:

Adding a new Testing Step

After creating a test case, you can save it in a *.ETF file in order to use this pre-defined test case later:

Loading Test File

After running the test, a message box appears with result, the protocol file will be written in "%appdata%":

Test OK

29.07.2020 15:28:34: Creating Test Brick: OneStep ...
29.07.2020 15:28:34: Creating Test Brick: FindRegExp ...
29.07.2020 15:28:34: Creating Test Brick: AssertEqual ...
29.07.2020 15:34:17: STEP 1
29.07.2020 15:34:20: STEP 2
29.07.2020 15:34:20: Search for OK
29.07.2020 15:34:20: Found 1 times
29.07.2020 15:34:20: STEP 3
29.07.2020 15:34:20: EQ
29.07.2020 15:35:38: **** Test OK! ****

Implementation

The interesting point is, how to change dynamically WPF GUI (code behind) by adding or deleting rows:

Changing XAML

This Grid is the object that we need to adjust. First we clear the "old" Grid and add all columns and rows:

private void CreateDataGrid()
{
 // Clear grid
 grdData.ColumnDefinitions.Clear();
 grdData.RowDefinitions.Clear();

 // Create Columns
 int nCol = 0;
 int nRow = 0;
 
 RowDefinition gridRow = new RowDefinition();
 gridRow.Height = new GridLength(25);
 grdData.RowDefinitions.Add(gridRow);

Also interesting is the possibility, to create a derived class from base instance:

Class Diagram

The TestBrickFactory "builds" a special "brick" from basic TestClass by knowing its name (Activator: https://docs.microsoft.com/en-us/dotnet/api/system.activator):

public static TestClass CreateTestBrick(TestClass oBase, string sName)
{
    Logger.Instance.Write("Creating Test Brick: " + sName + "...");
    string sBrickName = "TestingFramework.Model." + sName;

    var oType = Type.GetType(sBrickName);
    TestClass oClass = null;

    if (oType != null)
        oClass = (TestClass)Activator.CreateInstance(oType, oBase);

    return oClass;
}

Using the Code

It is very easy (thanks to reflection) to add the new testing "blocks!: this requires the creation of a new class that is derived from an abstract TestClass and the overwriting of a single virtual method ExecuteTestStep():

class OneStep : TestClass
{
    public OneStep(TestClass oBase) : base(oBase)
    {
        TestBrick = "OneStep";
    }

    public override string ExecuteTestStep()
    {
       // Do Smth!
    }
}

History

  • 29th July, 2020: Published (Vers. 1.0.1)
  • 30th July, 2020: Added Chapter "Implementation"
  • 10th August, 2020: Small update version 1.0.2

License

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

Share

About the Author

Leo Chapiro
Software Developer
Germany Germany

I'm a software developer living in Germany with my family (wife & 2 sons).
My hobbies: sport, traveling, books (former reading, now hearing).
Welcome to my homepage: http://leochapiro.de

Comments and Discussions

 
Questionit looks interesting Pin
Garth J Lancaster29-Jul-20 20:52
professionalGarth J Lancaster29-Jul-20 20:52 
AnswerRe: it looks interesting Pin
Leo Chapiro30-Jul-20 1:25
professionalLeo Chapiro30-Jul-20 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.