Andrew
Andrew

Reputation: 3706

How to get active TGUITestRunner from DUnit test?

TGUITestRunner form represents DUnit test results and created once by GUITestRunner.RunTest procedure:

procedure RunTest(test: ITest);
begin
  with TGUITestRunner.Create(nil) do
  begin
    try
      Suite := test;
      ShowModal;
    finally
      Free;
    end;
  end;
end;

I want to extend it at runtime by writing colored status messages. It is possible, because that status messages at the bottom of GUI are placed into TRichEdit. So I need to get the pointer to this form somewhere in my TTestCase.

Can I do that without fixing the DUnit's code? Maybe you can recommend some hack?

Upvotes: 3

Views: 337

Answers (1)

Warren  P
Warren P

Reputation: 69102

A "decoupled" way to do it might be to use some "embedded codes" inside your status messages:

Status('<blue>Testing');

From within the dUnit test framework, you could check if the initial character of a status message is '<', and extract the arguments such as color or whatever else, and then modify dUnit to handle it.

That way, your tests will still run on an unmodified dUnit test runner. Several years from now you might want to move to the latest dUnit test, and I don't recommend making any API changes, or trying to access the test runner objects. The APIs and things you can see from within a test are strictly controlled on purpose. It's a principle of proper object oriented design, which the creators of jUnit/xUnit/dUnit believe in intensely.

Upvotes: 1

Related Questions