Click here to Skip to main content
15,311,717 members
Articles / Desktop Programming / WPF
Posted 29 Jul 2020

Tagged as


10 bookmarked

Generic Testing Framework

Rate me:
Please Sign up or sign in to vote.
4.33/5 (6 votes)
30 Jul 2020CPOL1 min read
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.


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! ****


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

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

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:

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!


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


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


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:

Comments and Discussions

Questionit looks interesting Pin
Garth J Lancaster29-Jul-20 20:52
professionalGarth J Lancaster29-Jul-20 20:52 
but I also think you need more notes on defining a brick - looking at the FindRegExp.cs file in the download ...
using System.Text.RegularExpressions;

namespace TestingFramework.Model
    class FindRegExp : TestClass
        public FindRegExp(TestClass oBase) : base(oBase)
            TestBrick = "FindRegExp";

        public override string ExecuteTestStep()
            string sXml = InputFromOutput;
            string sFind = InputString;

            Logger.Instance.Write("Search for " + sFind);

            int nTimes = Regex.Matches(sXml, sFind).Count;
            Logger.Instance.Write("Found " + nTimes + " times");

            return nTimes.ToString();

A brick is going to be executed by 'calling'/running its 'ExecuteTestStep' Method : all Good

The Input to the brick is 'InputString', and the Output is (return)ed as a string from the ExecuteTestStep Method : all Good

sXml though .. hmmm, there's no obvious RegEx I can see, yet it's supposedly from "InputFromOutput" - where is InputFromOutput defined/derived/injected/conjured ?

vielen danke Smile | :)
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.