I am mocking an object supporting interface IClient for use in unit testing.
The interface itself is defined in another unit, ClientIF.
The interface references a TDetail defined in another unit, ldetail.
If I mock TDetail, I get an unidentified error on any function that uses TDetail.
[DCC Error] MockClient.pas(16): E2003 Undeclared identifier: 'GetDetailValue'
[DCC Error] MockClient.pas(16): E2003 Undeclared identifier: 'GetDetail'
[DCC Error] MockClient.pas(16): E2003 Undeclared identifier: 'GetActiveDetail'
[DCC Fatal Error] EmailPdfPropertiesGeneratorTests.pas(25): F2063 Could not compile used unit 'MockClient.pas'
I need to be able to mock both the interface and the supported detail object to test just the unit/interface I am working on. Otherwise it all ties to back end data which will be a testing nightmare.
Relevant MockClient.pas unit code
uses ClientIF, MockDetail;
TMockClient = class(TInterfacedObject, IClient)
FDetail: TDetail;
function GetDetailValue: TDetail;
function GetDetail: TDetail;
function GetActiveDetail: TDetail;
function GetDetailName: String;
end;
Relevant ClientIF.pas interface code
uses Classes, TaxConst, OSIConst, ldetail, clNotesIF, MissingDataDefIF,
ClientDataChangeEventIF;
type
IClient = interface
['{CFED9A10-1601-11D4-ACF6-005004889419}']
function GetDetailValue: TDetail;
function GetDetail: TDetail;
function GetActiveDetail: TDetail;
function GetDetailName: String;
end;
Relevant MockDetail.pas code
uses Classes;
type
TCodeValuesRec = class
private
fAmount: double;
fDesc: String;
fStateID: integer;
fCityID: String;
fSuffixCount: integer;
public
property Amount: double read fAmount write fAmount;
property Desc: String read fDesc write fDesc;
property StateID: integer read fStateID write fStateID;
property CityID: String read fCityID write fCityID;
property SuffixCount: integer read fSuffixCount write fSuffixCount;
end;
TDetail = class
private
FSeries: Integer;
FProp: Integer;
FPropCount: Integer;
FCodeValuesRec: TCodeValuesRec;
public
property Series: Integer read FSeries write FSeries;
property Prop: Integer read FProp write FProp;
property PropCount: Integer read FPropCount write FPropCount;
function GetCodeValuesRecord(WhichRecord: Integer):TCodeValuesRec;
constructor Create;
destructor Destroy; override;
end;
If I replace MockDetail with ldetail in the MockClient uses clause, it compiles, but, of course, the detail is one of the things I have to mock because it is one of the calls from the code under test.
We are trying to bring legacy code under test, which is a process. The code that is having this problem is actually new code, but the first time needed old objects for the test.
The goal for this question is to bring the new code under test, so creating a mock of the old interface (which contains an old class) so that MyClient.GetDetail will return the mock TDetail filled in with information that I can use in the object under test. If there is no way to fake the old code without refactoring it, then the process will have to wait.
If I can get the fake Client and Detail to do their fake work AND compile into the test framework (DUnit) so my tests can run against the real (new) code, that is sufficient, and all that can pursued right now.
We are currently on Delphi 2010 (upgraded this year) and will, EVENTUALLY, be going to the XEs, but I can't use the Mock Framework yet as it appears only to work with XE2.