Question

You can use TAbstractTest.Status procedure to show some debug messages in DUnit GUI during your tests.

But when I run the group of tests, I can see only the status messages from the last executed test. Can I see the complete log somehow, without selecting each single test to run?

Was it helpful?

Solution

The DUnit source code uses a IStatusListener interface and a public method

procedure TAbstractTest.SetStatusListener(Listener: IStatusListener);

which could be overriden to use a new implementation in your test classes. I have not tried it but it could be the cleanest solution.

OTHER TIPS

I have used 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 of that is somethig 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 really useful to identify what went wrong during the test. I haven't tried the SetStatusListener() but I think it should be the correct way if we want to show logging when a test has succeeded.

I would like to mimic the same behaviour as per Nunit where you can log customised messages on the output section.

Any better ideas?

First write a new procedure

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

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

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

you have to create LogStringList: TStringList in the initialization block of your test-unit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top