How do you use the Test Decorator in
fpcunit?
The Wiki (
https://wiki.freepascal.org/fpcunit#Test_decorator:_OneTimeSetup_and_OneTimeTearDown) describes how to create the Test Decorator and the benefit of the
OneTimeSetup method. However, it does not explain how to access it from within the
TestClass.
In this simplified example (which is essentially what the Wiki shows), how would I access the Filename property?
type
{ TTestLogSetup }
TTestLogSetup = class(TTestSetup)
private
F_Filename: string;
protected
procedure OneTimeSetup(); override;
procedure OneTimeTearDown(); override;
property Filename: string read F_Filename;
end;
...
implementation
{TTestLogSetup}
procedure TTestLogSetup.OneTimeSetup();
begin
F_Filename := './logger.log';
end;
procedure TTestLogSetup.OneTimeTearDown();
begin
end;
...
RegisterTestDecorator(TTestLogSetup, TTestLog);
This is the Test Case:
{ TTestLog }
TTestLog = class(TTestCase)
protected
//procedure SetUp; override;
//procedure TearDown; override;
published
procedure TestInit;
end;
implementation
...
{TTestLogSetup}
procedure TTestLog.TestInit;
var
sMsg: string;
oLog: TMadLogger;
begin
oLog := TMadLogger.Create( { I need the Filename here }, mllDevelopment);
try
sMsg := 'Start Logger';
oLog.LogInitMsg(sMsg);
oLog.Filepath := { I need the Filename here, too }; // Closes the file
oLog.Append := True;
sMsg := 'Continue Logging'; // Re-opens the file
oLog.LogInfoMsg(sMsg);
finally
oLog.Free();
end;
end;
I am trying to learn using this simplified example. Ultimately, I might want to create the Logger object once (in the Decorator) and use it throughout the multiple tests that will be written.
I have Googled this extensively, and I cannot find a definitive answer. I did find a post on Stack Exchange that suggested using class methods/properties but that answer was referring to DUnit and raised some controversy. I am searching for the
intention of how this is supposed to work.