How to view status messages in the DUnit GUI from all test cases at the same time?

You can use the TAbstractTest.Status procedure to display some debugging messages in the DUnit GUI during tests.

But when I run the test group, I can only see status messages from the last test run. Can I view the full log anyway without selecting each individual test?

+4
source share
3 answers

DUnit source code uses the IStatusListener interface and the public method

 procedure TAbstractTest.SetStatusListener(Listener: IStatusListener); 

which can be reevaluated to use the new implementation in your test classes. I have not tried, but this could be the cleanest solution.

+2
source

I used the Status () method, which will output the value when a failure occurs:

 procedure Test.TestGetStringListQueryValuesException; var ReturnValue: TList<String>; item: String; begin ReturnValue := FTest.GetStringListQueryValues; try for item in ReturnValue do begin Status('Value Processed: ' + item); CheckTrue(Pos('B', item) > 0, 'Wrong Value, Expected Item containing ''B'' but found: ' + item); end; finally ReturnValue.Free; end; end; 

The result is something like this:

 TestGetIntegerListQueryValuesException: ETestFailure at $0050B842 Wrong Value, Expected > 50 and < 60 but found: 61, expected: <True> but was: <False> Status Messages Value Processed: 52 Value Processed: 54 Value Processed: 55 Value Processed: 58 Value Processed: 59 Value Processed: 61 

It is very helpful to determine what went wrong during the test. I have not tried SetStatusListener (), but I think this should be the right way if we want to show the log when the test succeeded.

I would like to imitate the same behavior as in Nunit, where you can log custom messages in the output section.

Any better ideas?

+2
source

First write a new procedure

  procedure Log(text: string); begin LogStringList.Add(text); Status(text); end; 

replace all status() with Log() . And create a new test at the end of al tests

  procedure TestXXX.ShowLog; begin Status(LogStringList.Text); LogStringList.Clear; end; 

you need to create a LogStringList: TStringList in the initialization block of your test block.

0
source

Source: https://habr.com/ru/post/1399997/


All Articles