jeudi 4 février 2016

Delphi Unit Testing : Writing a simple spy for the CUT

Howdydlle,

I'm searching for a way to easily and concisely write a spy for the DUnitX testing framework under Delphi.

In the past, I've used very ugly ways of doing that using :

[TestFixture]
Test = class(TObject)
begin
  public
  [test]
  procedure Test1;
end;

TMyClass = class(TObject)
begin
  protected
  procedure MyProcedure; virtual;
end;

TMyTestClass = class(TMyClass)
begin
  protected
  fMyProcedureCalled : Boolean;
  procedure MyProcedure; override;
end

procedure TMyTestClass.MyProcedure;
begin
   fMyProcedureCalled := true;
   inherited;
end;

procedure Test.Test1
var aObj : TMyTestClass;
begin
   TMyTestClass.Create;
   Assert.IsTrue(aObj.fMyProcedureCalled);
end;

All of this code to check if a procedure was called. That's too verbose!

Is there a way to write a spy that would help me reduce that code?

Aucun commentaire:

Enregistrer un commentaire