DUnit: An XTreme testing framework for Delphi programs.
TActiveTest A test decorator for running tests in a separate thread TExceptionTestCase A test decorator for running tests expecting a specific exceptions to be thrown. TRepeatedTest A test decorator that runs a test repeatedly. TTestDecorator A Decorator for Tests. TTestSetup A Decorator to set up and tear down additional fixture state.
Author The DUnit Group.
HTML generated by Time2HELP
http://www.time2help.com
A test decorator for running tests in a separate threadUnit TestExtensions
Declaration TActiveTest = class (TTestDecorator ) Todo
HTML generated by Time2HELP
http://www.time2help.com
TExceptionTestCase Object
A test decorator for running tests expecting a specific exceptions to be thrown.Unit TestExtensions
Declaration TExceptionTestCase = class (TTestDecorator ) Todo
HTML generated by Time2HELP
http://www.time2help.com
A test decorator that runs a test repeatedly.Unit TestExtensions
Declaration TRepeatedTest = class (TTestDecorator )
Description Use TRepeatedTest to run a given test or suite a specific number of times.
TRepeatedTest Example function UnitTests: ITestSuite ;
begin
Result := TRepeatedTest.Create(ATestArithmetic.Suite, 10);
end ;
HTML generated by Time2HELP
http://www.time2help.com
CountEnabledTestCases method
Overrides the inherited behavior to included the number of repetitions.Applies to TRepeatedTest
Declaration Function CountEnabledTestCases: integer;
Returns Iterations * inherited CountEnabledTestCasesImplementation
function TRepeatedTest.CountEnabledTestCases: integer;
begin
Result := inherited CountTestCases * FTimesRepeat;
End ;
HTML generated by Time2HELP
http://www.time2help.com
Overrides the inherited behavior to included the number of repetitions.Applies to TRepeatedTest
Declaration Function CountTestCases: integer;
Returns Iterations * inherited CountTestCasesImplementation
function TRepeatedTest.CountTestCases: integer;
begin
Result := inherited CountTestCases * FTimesRepeat;
End ;
HTML generated by Time2HELP
http://www.time2help.com
Construct decorator that repeats the decorated test.Applies to TRepeatedTest
Declaration Constructor Create(ATest: ITest ; Iterations: integer; AName: string = '' );
Description The ITest parameter can hold a single test or a suite. The Name parameter is optional.
ATest The test to repeat. Itrations The number of times to repeat the test. AName An optional name to give to the decorator instance
Implementation constructor TRepeatedTest.Create(ATest: ITest ; Iterations: integer;
AName: string );
begin
inherited Create(ATest, AName);
FTimesRepeat := Iterations;
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TRepeatedTest
Declaration Function GetName: string ; Implementation
function TRepeatedTest.GetName: string ;
begin
Result := Format('%d x %s' , [FTimesRepeat, getTest.Name ]);
End ;
HTML generated by Time2HELP
http://www.time2help.com
Overrides the behavior of the base class as to execute the test repeatedly.Applies to TRepeatedTest
Declaration Procedure RunBare(ATestResult: TTestResult ); Implementation
procedure TRepeatedTest.RunBare(ATestResult: TTestResult );
var
i: integer;
begin
assert(assigned(ATestResult));
for i := 0 to FTimesRepeat - 1 do
begin
if ATestResult.shouldStop then
Break;
inherited RunBare(ATestResult);
end ;
End ;
HTML generated by Time2HELP
http://www.time2help.com
A Decorator for Tests.Unit TestExtensions
Declaration TTestDecorator = class (TAbstractTest , ITest , ITestDecorator )
Description Use TTestDecorator as the base class for defining new test decorators. Test decorator subclasses can be introduced to add behaviour before or after a test is run.
Introduced Public Properties
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestDecorator
Declaration Property Test : ITest Read GetTest ;
HTML generated by Time2HELP
http://www.time2help.com
CountEnabledTestCases method
Applies to TTestDecorator
Declaration Function CountEnabledTestCases: integer; Implementation
function TTestDecorator.CountEnabledTestCases: integer;
begin
if Enabled then
Result := FTest.countEnabledTestCases
else
Result := 0;
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestDecorator
Declaration Function CountTestCases: integer; Implementation
function TTestDecorator.CountTestCases: integer;
begin
if Enabled then
Result := FTest.countTestCases
else
Result := 0;
End ;
HTML generated by Time2HELP
http://www.time2help.com
Decorate a test.Applies to TTestDecorator
Declaration Constructor Create(ATest: ITest ; AName: string = '' );
Description If no name parameter is given, the decorator will be named as the decorated test, with some extra information prepended.
ATest The test to decorate. AName Optional name to give to the decorator.
Implementation constructor TTestDecorator.Create(ATest: ITest ; AName: string = '' );
begin
if AName <> '' then
inherited Create(AName)
else
inherited Create(ATest.name );
FTest := ATest;
FTests:= TInterfaceList.Create;
FTests.Add(FTest);
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestDecorator
Declaration Function GetName: string ; Implementation
function TTestDecorator.GetName: string ;
begin
Result := Format('[d] %s' , [getTest.Name ]);
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestDecorator
Declaration Function GetTest: ITest ;Implementation
function TTestDecorator.GetTest: ITest ;
begin
Result := FTest;
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestDecorator
Declaration Procedure LoadConfiguration(const iniFile :TIniFile; const section :string ); Implementation
procedure TTestDecorator.LoadConfiguration(const iniFile: TIniFile; const section: string );
begin
FTest.LoadConfiguration(iniFile, section)
End ;
HTML generated by Time2HELP
http://www.time2help.com
Overrides the inherited behavior and executes the decorated test's RunBare insteadApplies to TTestDecorator
Declaration Procedure RunBare(ATestResult: TTestResult ); Implementation
procedure TTestDecorator.RunBare(ATestResult: TTestResult );
begin
FTest.RunBare(ATestResult);
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestDecorator
Declaration Procedure SaveConfiguration(const iniFile :TIniFile; const section :string ); Implementation
procedure TTestDecorator.SaveConfiguration(const iniFile: TIniFile; const section: string );
begin
FTest.SaveConfiguration(iniFile, section)
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestDecorator
Declaration Function Tests: IInterfaceList; Implementation
function TTestDecorator.tests: IInterfaceList;
begin
Result := FTests;
End ;
HTML generated by Time2HELP
http://www.time2help.com
A Decorator to set up and tear down additional fixture state.Unit TestExtensions
Declaration TTestSetup = class (TTestDecorator )
Description Subclass TestSetup and insert it into your tests when you want to set up additional state once before the tests are run.
TTestSetup Example function UnitTests: ITest ;
begin
Result := TSetubDBDecorator.Create(TDatabaseTests.Suite, 10);
end ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestSetup
Declaration Constructor Create(ATest: ITest ; AName: string = '' );Implementation
constructor TTestSetup.Create(ATest: ITest ; AName: string = '' );
begin
inherited Create(ATest, AName);
End ;
HTML generated by Time2HELP
http://www.time2help.com
Applies to TTestSetup
Declaration Procedure RunBare(ATestResult: TTestResult ); Implementation
procedure TTestSetup.RunBare(ATestResult: TTestResult );
begin
try
Setup;
except
on E: Exception do
assert(false, 'Setup failed: ' + e.message );
end ;
try
inherited RunBare(ATestResult);
finally
try
TearDown;
except
on E: Exception do
assert(false, 'Teardown failed: ' + e.message );
end ;
end ;
End ;
HTML generated by Time2HELP
http://www.time2help.com
Sets up the fixture.Applies to TTestSetup
Declaration Procedure Setup;
Description Override to set up additional fixture state.
HTML generated by Time2HELP
http://www.time2help.com
Tears down the fixture.Applies to TTestSetup
Declaration Procedure TearDown;
Description Override to tear down the additional fixture state.
HTML generated by Time2HELP
http://www.time2help.com
General interface for test decoratorsUnit TestExtensions
Declaration ITestDecorator = interface (ITest )
HTML generated by Time2HELP
http://www.time2help.com
Applies to ITestDecorator
Declaration Property Test : ITest Read GetTest ;
HTML generated by Time2HELP
http://www.time2help.com
Get the decorated testApplies to ITestDecorator
Declaration Function GetTest: ITest ;
Returns The decorated test
HTML generated by Time2HELP
http://www.time2help.com