TextOutputGenerated Event

Occurs when text output is generated by the currently running XJEase TestFunction. This event is fired from an arbitrary thread.

Type: Runner

Namespace: XJTAG.Integration.XJRunner

Syntax

public event EventHandler<TextOutputGeneratedEventArgs> TextOutputGenerated

Remarks

This event is fired from the thread on which the test code is running. You therefore need to be careful about synchronising access to your data structures and, if your code accesses any user interface controls, you will need to use BeginInvoke to ensure that you access methods and properties from the appropriate thread.

Example

This example shows how to handle the TextOutputGenerated Event, in a console application, and display the generated text in different colours depending on the type of text produced.

class Program
{
    static Runner runner;
    static TestCollection testList;

    static void Main(string[] args)
    {
        /*
         * ...
         * Code to obtain Runner object from project and get test list.
         * ...
         */

        // Subscribe to TestingStarted event.
        runner.TextOutputGenerated += runner_TextOutputGenerated;

        /*
         * ...
         * Code running tests and disposal of Runner Integration objects.
         * ...
         */
    }

    static void runner_TextOutputGenerated(object sender, TextOutputGeneratedEventArgs e)
    {
        // Here we are displaying any pass messages with a green background and any fail messages
        // with red. Any other message will be displayed in the console's pre-set colour scheme. We
        // can determine the type of message produced by using the TextOutputGeneratedEventArgs.
        switch (e.Type)
        {
            case OutputTextType.Pass:
                Console.BackgroundColor = ConsoleColor.DarkGreen;
                break;
            case OutputTextType.Error:
                Console.BackgroundColor = ConsoleColor.DarkRed;
                break;
            default:
                Console.ResetColor();
                break;
        }

        Console.Write(e.Text);
    }
}