TestFramework Unit
Classes Interfaces Types Routines Const
The testing framework.

Description
The TestFramework unit contains all the core definitions in the library, such as:

The TTestCase class should be ther first stop for all new users.

Classes
EBreakingTestFailure Failed tests throw this exception when the framework is set to cause the Delphi IDE debugger to break on test failures.
EStopTestsFailure Tests can throw this exception to stop any further testing
ETestError The framework will throw this type of exception when it encounters an error in a test case
ETestFailure Failed tests throw this exception.
TAbstractTest Provides the basic functionality tha all implementors of ITest must provide.
TMethodEnumerator Enumerates the published methods of a class.
TTestCase A test case defines the fixture to run multiple tests.
TTestFailure A TTestFailure collects a failed test together with information about the exception which caused the test to fail.
TTestResult A TTestResult collects the results of executing a test case.
TTestSuite A TTestSuite is a Composite of Tests, implementing the ITestSuite interface.

Interfaces
ITest ITest represents a test that can be run.
ITestListener A Listener for test progress.
ITestSuite An ITestSuite is a Composite of Tests.

Types
TTestCaseClass Used to pass a class reference to a descendant of TTestCase to TTestSuite.Create.
TTestMethod A method on a TTestCase descendent which implements a unit test.

Routines
CallerAddr Returns the address that the calling procedure will return to.
MakeTestSuite Create a named test suite out a series of tests
MakeTestSuites Create a test suite hierarchy out of a series of TTestCase descendants
RegisteredTests Return a TestSuite containing all registered tests.
RegisterTest Register a test.
RegisterTests Register a series of tests under the given path.
RegisterTestSuites Register a series of test suites consisting of the published methods of the TTestCase descendants passed in the classes array.
RunRegisteredTests Run registered tests using default features and notifying the given set of listeners of testing events.
RunTest Run a test using default features and notifying the given set of listeners of testing events.
SetBreakOnFailures Allow the IDE to break on failure exceptions.
TestSuiteOf Create a test suite out of the published methods in a TTestCase descendant

Global Constants
rcs_id This is the version of the testframework which this documentation describes.

Author
The DUnit Group.


HTML generated by Time2HELP
http://www.time2help.com
EBreakingTestFailure Object
Methods
Failed tests throw this exception when the framework is set to cause the Delphi IDE debugger to break on test failures.

Unit
TestFramework

Declaration
EBreakingTestFailure = class(Exception)

Description
Exceptions of this type will be reported as test failures

Introduced Methods
Create


HTML generated by Time2HELP
http://www.time2help.com
Create method

Applies to
EBreakingTestFailure

Declaration
Constructor Create;

Implementation

constructor EBreakingTestFailure.Create;
begin
   inherited Create('')
End;


HTML generated by Time2HELP
http://www.time2help.com
EStopTestsFailure Object
Tests can throw this exception to stop any further testing

Unit
TestFramework

Declaration
EStopTestsFailure = class(ETestFailure)


HTML generated by Time2HELP
http://www.time2help.com
ETestError Object
The framework will throw this type of exception when it encounters an error in a test case

Unit
TestFramework

Declaration
ETestError = class(Exception)


HTML generated by Time2HELP
http://www.time2help.com
ETestFailure Object
Methods
Failed tests throw this exception.

Unit
TestFramework

Declaration
ETestFailure = class(EAbort)

Description
Exceptions of this type will be reported as test failures

Introduced Methods
Create

See Also


HTML generated by Time2HELP
http://www.time2help.com
Create method

Applies to
ETestFailure

Declaration
Constructor Create;

Implementation

constructor ETestFailure.Create;
begin
   inherited Create('')
End;


HTML generated by Time2HELP
http://www.time2help.com
TAbstractTest Object
Properties Methods
Provides the basic functionality tha all implementors of ITest must provide.

Unit
TestFramework

Declaration
TAbstractTest = class(TInterfacedObject, ITest)

Description
Basically: having a name, and having an enabled, disabled state

Introduced Public Properties
Enabled The enabled state of the test.
Name The test's name.

Introduced Methods
CountEnabledTestCases
CountTestCases
Create  Create an instance of a test fixture to run the named test.
getEnabled
GetName
LoadConfiguration  Load a previously saved state.
Run  A convenience method to run this test, collecting the results with a default TestResult object.
RunBare
SaveConfiguration
setEnabled
Tests


HTML generated by Time2HELP
http://www.time2help.com
Enabled property
The enabled state of the test.

Applies to
TAbstractTest

Declaration
Property Enabled : boolean Read GetEnabled Write SetEnabled;

See Also


HTML generated by Time2HELP
http://www.time2help.com
Name property
The test's name.

Applies to
TAbstractTest

Declaration
Property Name : string Read GetName;

See Also


HTML generated by Time2HELP
http://www.time2help.com
CountEnabledTestCases method
Count the number of contained enabled tests.

Applies to
TAbstractTest

Declaration
Function CountEnabledTestCases: integer;

Implementation

function TAbstractTest.CountEnabledTestCases: integer;
begin
  if GetEnabled then
    Result := 1
  else
    Result := 0
End;


HTML generated by Time2HELP
http://www.time2help.com
CountTestCases method
Count contained tests.

Applies to
TAbstractTest

Declaration
Function CountTestCases: integer;

Implementation

function TAbstractTest.CountTestCases: integer;
begin
  Result := 1;
End;


HTML generated by Time2HELP
http://www.time2help.com
Create method
Create an instance of a test fixture to run the named test.

Applies to
TAbstractTest

Declaration
Constructor Create(Name: string);

Description
Create a test fixture capabile of running a single testcase. The test case that will be run is the method called MethodName, which must be declared in the published section of a sub-class of TTestCase.

Implementation

constructor TAbstractTest.Create(Name: string);
begin
  inherited Create;
  FTestName := Name;
  FEnabled  := true;
End;


HTML generated by Time2HELP
http://www.time2help.com
getEnabled method
Get the enabled state of the test.

Applies to
TAbstractTest

Declaration
Function getEnabled: boolean;

Implementation

function TAbstractTest.getEnabled: boolean;
begin
  Result := fEnabled
End;


HTML generated by Time2HELP
http://www.time2help.com
GetName method
Get the name of the test.

Applies to
TAbstractTest

Declaration
Function GetName: string;

Implementation

function TAbstractTest.GetName: string;
begin
  Result := fTestName
End;


HTML generated by Time2HELP
http://www.time2help.com
LoadConfiguration method
Load a previously saved state.

Applies to
TAbstractTest

Declaration
Procedure LoadConfiguration(const fileName :string);

Description
Load the enabled/disabled state of this and contained tests.

Parameters
fileName The name of the .INI file to read the configuration from.

See Also

Implementation

procedure TAbstractTest.LoadConfiguration(const fileName: string);
var
  f :TIniFile;
begin
  f := TIniFile.Create(fileName);
  try
    LoadConfiguration(f, 'Tests')
  finally
    f.free
  end
End;


HTML generated by Time2HELP
http://www.time2help.com
Run method
A convenience method to run this test, collecting the results with a default TestResult object.

Applies to
TAbstractTest

Declaration
Function Run: TTestResult;

Description
Run will Create a TTestResult, run this test case and collect any TTestFailure into the TTestResult. The caller is responsible for freeing the returned TTestResult.

Returns
A TTestResult with the results of running this test.

Implementation

function TAbstractTest.Run: TTestResult;
var
  testResult : TTestResult;
begin
  testResult := TTestResult.Create;
  try
    testResult.RunSuite(self);
  except
    testResult.Free;
    raise;
  end;
  Result := testResult;
End;


HTML generated by Time2HELP
http://www.time2help.com
RunBare method
Runs a test and collects its result in a TTestResult instance.

Applies to
TAbstractTest

Declaration
Procedure RunBare(testResult: TTestResult);

Parameters
testResult the results of running this test are collected into this TTestResult object.


HTML generated by Time2HELP
http://www.time2help.com
SaveConfiguration method
Save the current state.

Applies to
TAbstractTest

Declaration
Procedure SaveConfiguration(const fileName :string);

See Also

Implementation

procedure TAbstractTest.SaveConfiguration(const fileName: string);
var
  f :TIniFile;
begin
  f := TIniFile.Create(fileName);
  try
    SaveConfiguration(f, 'Tests')
  finally
    f.free
  end
End;


HTML generated by Time2HELP
http://www.time2help.com
setEnabled method
Set the enabled state of the test.

Applies to
TAbstractTest

Declaration
Procedure setEnabled(value: boolean);

Implementation

procedure TAbstractTest.setEnabled(value: boolean);
begin
  fEnabled := value;
End;


HTML generated by Time2HELP
http://www.time2help.com
Tests method
The list of contained tests.

Applies to
TAbstractTest

Declaration
Function Tests: IInterfaceList;

See Also

Implementation

function TAbstractTest.Tests: IInterfaceList;
begin
   if EmptyTestList = nil then
     EmptyTestList := TInterfaceList.Create;
   Result := EmptyTestList;
End;


HTML generated by Time2HELP
http://www.time2help.com
TMethodEnumerator Object
Properties Methods
Enumerates the published methods of a class.

Unit
TestFramework

Declaration
TMethodEnumerator = class(TObject)

Description
This class is used by the framework to make the creation of test suites easy. Users of the framework should never have to use this class directly

Introduced Public Properties
MethodCount 
NameOfMethod 

Introduced Methods
Create
GetMethodCount
GetNameOfMethod

See Also


HTML generated by Time2HELP
http://www.time2help.com
MethodCount property

Applies to
TMethodEnumerator

Declaration
Property MethodCount : integer Read GetMethodCount;


HTML generated by Time2HELP
http://www.time2help.com
NameOfMethod property

Applies to
TMethodEnumerator

Declaration
Property NameOfMethod[index:integer] : string Read GetNameOfMethod;


HTML generated by Time2HELP
http://www.time2help.com
Create method

Applies to
TMethodEnumerator

Declaration
Constructor Create(AClass: TClass);

Implementation

constructor TMethodEnumerator.Create(AClass: TClass);
type
  TMethodTable = packed record
    count: SmallInt;
  //[...methods...]
  end;
var
  table: ^TMethodTable;
  name : ^ShortString;
  i, j : Integer;
begin
  inherited Create;
  while aclass <> nil do
  begin
    // *** HACK ALERT *** !!!
    // Review System.MethodName to grok how this method works
    asm
      mov  EAX, [aclass]
      mov  EAX,[EAX].vmtMethodTable { fetch pointer to method table }
      mov  [table], EAX
    end;
    if table <> nil then
    begin
      name := Pointer(PChar(table) + 8);
      for i := 1 to table.count do
      begin
        // check if we've seen the method name
        j := Low(FMethodNameList);
        while (j <= High(FMethodNameList)) 
        and (name^ <> FMethodNameList[j]) do
          inc(j);
        // if we've seen the name, then the method has probably been overridden
        if j <= High(FMethodNameList) then
          CONTINUE;
        SetLength(FMethodNameList,length(FMethodNameList)+1);
        FMethodNameList[j] := name^;
        name := Pointer(PChar(name) + length(name^) + 7)
      end;
    end;
    aclass := aclass.ClassParent;
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
GetMethodCount method

Applies to
TMethodEnumerator

Declaration
Function GetMethodCount: Integer;

Implementation

function TMethodEnumerator.GetMethodCount: Integer;
begin
  Result := Length(FMethodNameList);
End;


HTML generated by Time2HELP
http://www.time2help.com
GetNameOfMethod method

Applies to
TMethodEnumerator

Declaration
Function GetNameOfMethod(Index: integer): string;

Implementation

function TMethodEnumerator.GetNameOfMethod(Index: integer): string;
begin
  Result := FMethodNameList[Index];
End;


HTML generated by Time2HELP
http://www.time2help.com
TTestCase Object
Methods
A test case defines the fixture to run multiple tests.

Unit
TestFramework

Declaration
TTestCase = class(TAbstractTest, ITest)

Description
To define a test case
1) implement a subclass of TestCase
2) define instance variables that store the state of the fixture
3) initialize the fixture state by overriding setUp
4) clean-up after a test by overriding tearDown.
Each test runs in its own fixture so there can be no side effects among test runs. Here is an example:
  interface

  type
    TMathTest = class(TTestCase)
    private
      fValue1,
      fValue2: Float;
      procedure testAdd;
    public
      procedure setUp; override;
    end;

  implementation

  procedure TMathTest.setUp;
  begin
    fValue1 := 2.0;
    fValue2 := 3.0;
  end;
For each test implement a method which interacts with the fixture. Verify the expected results with tests specified by calling check with a boolean and an optional message.
  procedure TMathTest.testAdd;
  var
    testResult: Float;
  begin
    testResult := fValue1 + fValue2;
    check(testResult = 5.0);
  end;
see TTestResult see TTestSuite

Introduced Methods
Check  Checks that a condition is met.
CheckEquals
CheckNotEquals
CheckNotNull
CheckNull
CheckSame
Create  Create an instance of a test fixture to run the named test.
EqualsErrorMessage
Fail  Report a test failure.
FailEquals
FailNotEquals
FailNotSame
NotEqualsErrorMessage
NotSameErrorMessage
Run
RunBare  Runs the test case and collects the results in TestResult.
RunTest  Perform the test.
SetUp  Sets up the fixture, for example, open a network connection.
StopTests  Stops testing.
Suite  Create a test suite.
TearDown  Tears down the fixture, for example, close a network connection.


HTML generated by Time2HELP
http://www.time2help.com
Check method
Checks that a condition is met.

Applies to
TTestCase

Declaration
Procedure Check(condition: boolean; msg: string = '');

Description
Logs a failure using the optional message string if not.

Parameters
condition The condition to check.
msg An optional message use if the check fails.

Implementation

procedure TTestCase.Check(condition :boolean; msg :string);
begin
    if (not condition) then
        Fail(msg, CallerAddr);
End;


HTML generated by Time2HELP
http://www.time2help.com
CheckEquals method

Applies to
TTestCase

Declaration
Procedure CheckEquals(expected, actual :double; delta :double = 0; msg :string = '');

Implementation

procedure TTestCase.CheckEquals( expected,
                                 actual    :double;
                                 delta     :double = 0;
                                 msg       :string = '');
begin
    if (abs(expected-actual) > delta) then
        FailNotEquals(FloatToStr(expected), FloatToStr(actual), msg, CallerAddr);
End;


HTML generated by Time2HELP
http://www.time2help.com
CheckNotEquals method

Applies to
TTestCase

Declaration
Procedure CheckNotEquals(expected, actual :integer; msg :string = '');

Implementation

procedure TTestCase.CheckNotEquals(expected, actual :integer; msg :string = '');
begin
  if expected <> actual then
    FailNotEquals(IntToStr(expected), IntToStr(actual), msg, CallerAddr);
End;


HTML generated by Time2HELP
http://www.time2help.com
CheckNotNull method

Applies to
TTestCase

Declaration
Procedure CheckNotNull(obj :IUnknown; msg :string = '');


HTML generated by Time2HELP
http://www.time2help.com
CheckNull method

Applies to
TTestCase

Declaration
Procedure CheckNull(obj :IUnknown; msg :string = '');


HTML generated by Time2HELP
http://www.time2help.com
CheckSame method

Applies to
TTestCase

Declaration
Procedure CheckSame(expected, actual :IUnknown; msg :string = '');

Implementation

procedure TTestCase.CheckSame(expected, actual: IUnknown; msg :string = '');
begin
    if (expected = actual) then
        exit;
    FailNotSame(PtrToStr(Pointer(expected)), PtrToStr(Pointer(actual)), msg, CallerAddr);
End;


HTML generated by Time2HELP
http://www.time2help.com
Create method
Create an instance of a test fixture to run the named test.

Applies to
TTestCase

Declaration
Constructor Create(MethodName: string);

Description
Create a test fixture capabile of running a single testcase. The test case that will be run is the method called MethodName, which must be declared in the published section of a sub-class of TTestCase. see @TTestSuite see @ITestSuite

Implementation

constructor TTestCase.Create(MethodName: string);
var
  RunMethod: TMethod;
begin
  assert(length(MethodName) >0);
  assert(assigned(MethodAddress(MethodName)));

  inherited Create(MethodName);
  RunMethod.code := MethodAddress(MethodName);
  RunMethod.Data := self;
  fMethod := TTestMethod(RunMethod);

  assert(assigned(fMethod));
End;


HTML generated by Time2HELP
http://www.time2help.com
EqualsErrorMessage method

Applies to
TTestCase

Declaration
Function EqualsErrorMessage(expected, actual, msg: string): string;

Implementation

function TTestCase.EqualsErrorMessage(expected, actual :string; msg :string) :string;
begin
    if (msg <> '') then
        msg := msg + ', ';
    Result := Format('%s expected and actual were:<%s>', [msg, expected])
End;


HTML generated by Time2HELP
http://www.time2help.com
Fail method
Report a test failure.

Applies to
TTestCase

Declaration
Procedure Fail(msg :string; errorAddr :Pointer = nil);

Description
Reports a failure to all TestListeners using the provided message.

Parameters
msg The optional message.

Implementation

procedure TTestCase.Fail(msg: string; errorAddr :Pointer = nil);
begin
  if errorAddr = nil then
    raise __FailureExceptionClass.Create(msg) at CallerAddr
  else
    raise __FailureExceptionClass.Create(msg) at errorAddr;
End;


HTML generated by Time2HELP
http://www.time2help.com
FailEquals method

Applies to
TTestCase

Declaration
Procedure FailEquals(expected, actual: string; msg: string = ''; errorAddr :Pointer = nil);

Implementation

procedure TTestCase.FailEquals( expected,
                                actual    :string;
                                msg       :string = '';
                                errorAddr :Pointer = nil);
begin
    Fail(EqualsErrorMessage(expected, actual, msg), errorAddr);
End;


HTML generated by Time2HELP
http://www.time2help.com
FailNotEquals method

Applies to
TTestCase

Declaration
Procedure FailNotEquals(expected, actual: string; msg: string = ''; errorAddr :Pointer = nil);

Implementation

procedure TTestCase.FailNotEquals( expected,
                                   actual    :string;
                                   msg       :string = '';
                                   errorAddr :Pointer = nil);
begin
    Fail(notEqualsErrorMessage(expected, actual, msg), errorAddr);
End;


HTML generated by Time2HELP
http://www.time2help.com
FailNotSame method

Applies to
TTestCase

Declaration
Procedure FailNotSame(expected, actual: string; msg: string = ''; errorAddr :Pointer = nil);

Implementation

procedure TTestCase.FailNotSame( expected,
                                 actual    :string;
                                 msg       :string = '';
                                 errorAddr :Pointer = nil);
begin
    Fail(NotSameErrorMessage(expected, actual, msg), errorAddr);
End;


HTML generated by Time2HELP
http://www.time2help.com
NotEqualsErrorMessage method

Applies to
TTestCase

Declaration
Function NotEqualsErrorMessage(expected, actual, msg: string): string;

Implementation

function TTestCase.NotEqualsErrorMessage(expected, actual :string; msg :string) :string;
begin
    if (msg <> '') then
        msg := msg + ', ';
    Result := Format('%s expected:<%s> but was:<%s>', [msg, expected, actual])
End;


HTML generated by Time2HELP
http://www.time2help.com
NotSameErrorMessage method

Applies to
TTestCase

Declaration
Function NotSameErrorMessage(expected, actual, msg: string): string;

Implementation

function TTestCase.NotSameErrorMessage(expected, actual, msg: string): string;
begin
    if (msg <> '') then
        msg := msg + ', ';
    Result := Format('%s expected:<%s> but was:<%s>', [msg, expected, actual])
End;


HTML generated by Time2HELP
http://www.time2help.com
Run method
Makes the given testResult run this test.

Applies to
TTestCase

Declaration
Procedure Run(testResult: TTestResult);

Parameters
testResult Where test results will be accumulated.

Implementation

procedure TTestCase.Run(testResult: TTestResult);
begin
  testResult.RunSuite(self);
End;


HTML generated by Time2HELP
http://www.time2help.com
RunBare method
Runs the test case and collects the results in TestResult.

Applies to
TTestCase

Declaration
Procedure RunBare(testResult: TTestResult);

Description
This is the template method that defines the control flow for running a test case.

Implementation

procedure TTestCase.RunBare(testResult: TTestResult);
begin
  assert(assigned(testResult));

  if getEnabled then
  begin
    testResult.Run(self);
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
RunTest method
Perform the test.

Applies to
TTestCase

Declaration
Procedure RunTest;

Description
Performs the test. The pre-conditions for the test must already have been met. runTest may leave the system in an unknown state. Do not override this function to Create testcases.

Raises
ETestFailure The test failed.
Exception An error occcurred while running this test.

Implementation

procedure TTestCase.RunTest;
begin
  assert(assigned(fMethod), 'Method "' + FTestName + '" not found');
  fMethod;
End;


HTML generated by Time2HELP
http://www.time2help.com
SetUp method
Sets up the fixture, for example, open a network connection.

Applies to
TTestCase

Declaration
Procedure SetUp;

Description
This method is used to ensure that state of the application is in a known state before running any test cases. This method is called before each test is executed in this TTestCase. Override this method to add code to setup the preconditions for the testcases declared in descendants of TTestCase.

See Also

Implementation

procedure TTestCase.SetUp;
begin
End;


HTML generated by Time2HELP
http://www.time2help.com
StopTests method
Stops testing.

Applies to
TTestCase

Declaration
Procedure StopTests(msg :String = '');

Description
Throws EStopTestsFailure to Stop further testing.

Parameters
msg An optional message to attach to the thrown exception.

Raises
EStopTestsFailure 

See Also

Implementation

procedure TTestCase.StopTests(msg :String);
begin
  raise EStopTestsFailure.Create(msg);
End;


HTML generated by Time2HELP
http://www.time2help.com
Suite method
Create a test suite.

Applies to
TTestCase

Declaration
Class function Suite: ITestSuite;

Description
Creates a test suite composed of the published methods in the current TTestCase class.

See Also

Implementation

function TTestCase.Suite: ITestSuite;
begin
  Result := TestSuiteOf(Self);
End;


HTML generated by Time2HELP
http://www.time2help.com
TearDown method
Tears down the fixture, for example, close a network connection.

Applies to
TTestCase

Declaration
Procedure TearDown;

Description
This method is called after each test in this TTestCase is executed. Override this method to de-allocate any resources allocated by SetUp.

See Also

Implementation

procedure TTestCase.TearDown;
begin
End;


HTML generated by Time2HELP
http://www.time2help.com
TTestFailure Object
Methods
A TTestFailure collects a failed test together with information about the exception which caused the test to fail.

Unit
TestFramework

Declaration
TTestFailure = class(TObject)

Description
TTestCase descendants do not need to manipulate TTestFailures directly. TTestFailures are used by TTestResult to keep track of the results of running a set of tests. TTestFailure is used by the test runners to report test failures. see TTestResult

Introduced Methods
Create  Constructs a record of a failed test.
FailedTest  Returns the test which failed.
ThrownExceptionMessage
ThrownExceptionName


HTML generated by Time2HELP
http://www.time2help.com
Create method
Constructs a record of a failed test.

Applies to
TTestFailure

Declaration
Constructor Create(failedTest: ITest; thrownException: Exception; msg :string = '');

Description
Constructs a TTestFailure with the given test and the exception which occurred while running that test. see TTestResult.AddError see TTestResult.AddFailure

Implementation

constructor TTestFailure.Create(FailedTest: ITest; thrownException: Exception; msg :string);
begin
  assert(assigned(thrownException));

  inherited Create;
  fFailedTest := FailedTest;
  fThrownExceptionName := thrownException.ClassName;
  fThrownExceptionMessage := msg + thrownException.message;
End;


HTML generated by Time2HELP
http://www.time2help.com
FailedTest method
Returns the test which failed.

Applies to
TTestFailure

Declaration
Function FailedTest: ITest;

Description
see ITest

Implementation

function TTestFailure.FailedTest: ITest;
begin
  result := fFailedTest;
End;


HTML generated by Time2HELP
http://www.time2help.com
ThrownExceptionMessage method
Returns the message from the exception which triggered the failure of this test.

Applies to
TTestFailure

Declaration
Function ThrownExceptionMessage: string;

Implementation

function TTestFailure.ThrownExceptionMessage: string;
begin
  result := fThrownExceptionMessage;
End;


HTML generated by Time2HELP
http://www.time2help.com
ThrownExceptionName method
Returns the name of the exception which triggered the failure of this test.

Applies to
TTestFailure

Declaration
Function ThrownExceptionName: string;

Implementation

function TTestFailure.ThrownExceptionName: string;
begin
  result := fThrownExceptionName;
End;


HTML generated by Time2HELP
http://www.time2help.com
TTestResult Object
Methods
A TTestResult collects the results of executing a test case.

Unit
TestFramework

Declaration
TTestResult = class(TObject)

Description
It is an instance of the Collecting Parameter pattern. The test framework distinguishes between failures and errors. A failure is anticipated and checked for with checks. Errors are unanticipated problems that raise an exception. see Check see ITest

Introduced Methods
AddError  Adds an error to the list of errors.
AddFailure  Adds a failure to the list of failures.
addListener
Create
destroy
EndTest  Informs the result that a test was completed.
ErrorCount
errors
FailureCount
Failures
Run  Runs a TestCase.
RunCount
RunSuite  Runs a test.
ShouldStop
StartTest  Informs the result that a test will be started.
Stop
TestingEnds
TestingStarts
WasStopped
WasSuccessful


HTML generated by Time2HELP
http://www.time2help.com
AddError method
Adds an error to the list of errors.

Applies to
TTestResult

Declaration
Function AddError(test: ITest; e: Exception; msg :string = ''): TTestFailure;

Description
Creates a TTestFailure recording that an error occurred in test. Notifies any registered ITestListeners that an error occurred. The TTestFailure returned should not be freed.

Parameters
test The test with an error.
The exception that caused the error.

Returns
the TTestFailure object representing this error.

Implementation

function TTestResult.AddError(test: ITest; e: Exception; msg :string): TTestFailure;
var
  i: integer;
  error : TTestFailure;
begin
  assert(assigned(test));
  assert(assigned(e));
  assert(assigned(fErrors));

  error := TTestFailure.Create(test, e, msg);
  fErrors.add(error);
  for i := 0 to fListeners.count - 1 do
  begin
    (fListeners[i] as ITestListener).AddError(error);
  end;

  assert(assigned(error));
  Result := error;
End;


HTML generated by Time2HELP
http://www.time2help.com
AddFailure method
Adds a failure to the list of failures.

Applies to
TTestResult

Declaration
Function AddFailure(test: ITest; e: Exception): TTestFailure;

Description
Creates a TTestFailure recording that a failure occurred in test. Notifies any registered ITestListeners that a failure occurred. The TTestFailure returned should not be freed.

Parameters
test The test that failed.
The exception that caused the failure.

Returns
The TTestFailure object representing this failure.

Implementation

function TTestResult.AddFailure(test: ITest; e: Exception): TTestFailure;
var
  i: integer;
  Failure : TTestFailure;
begin
  assert(assigned(test));
  assert(assigned(e));
  assert(assigned(fFailures));

  Failure := TTestFailure.Create(test, e);
  fFailures.add(Failure);
  for i := 0 to fListeners.count - 1 do
  begin
    (fListeners[i] as ITestListener).AddFailure(Failure);
  end;

  assert(assigned(Failure));
  Result := Failure;
End;


HTML generated by Time2HELP
http://www.time2help.com
addListener method
Registers an ITestListener to listen to the status of the testing.

Applies to
TTestResult

Declaration
Procedure addListener(listener: ITestListener);

Implementation

procedure TTestResult.addListener(listener: ITestListener);
begin
  assert(assigned(listener), 'listener is nil');
  fListeners.add(listener);
End;


HTML generated by Time2HELP
http://www.time2help.com
Create method
construct a TTestCase.

Applies to
TTestResult

Declaration
Constructor Create;

Implementation

constructor TTestResult.Create;
begin
  inherited Create;
  fFailures := TList.Create;
  fErrors := TList.Create;
  fListeners := TInterfaceList.Create;
  fRunTests := 0;
  fStop := false;
End;


HTML generated by Time2HELP
http://www.time2help.com
destroy method

Applies to
TTestResult

Declaration
Destructor destroy;

Implementation

destructor TTestResult.destroy;
var
  i: Integer;
begin
  fListeners := nil;
  for i := 0 to fErrors.Count - 1 do
  begin
    TTestFailure(fErrors[i]).Free;
  end;
  fErrors.Free;
  for i := 0 to fFailures.Count - 1 do
  begin
    TTestFailure(fFailures[i]).Free;
  end;
  fFailures.Free;
  inherited Destroy;
End;


HTML generated by Time2HELP
http://www.time2help.com
EndTest method
Informs the result that a test was completed.

Applies to
TTestResult

Declaration
Procedure EndTest(test: TTestCase);

Description
Notify any registered ITestListener that a test was completed.

Implementation

procedure TTestResult.EndTest(test: TTestCase);
var
  i: integer;
begin
  assert(assigned(fListeners));

  for i := 0 to fListeners.count - 1 do
  begin
    (fListeners[i] as ITestListener).EndTest(test);
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
ErrorCount method
Gets the number of detected errors.

Applies to
TTestResult

Declaration
Function ErrorCount: integer;

Implementation

function TTestResult.ErrorCount: integer;
begin
  assert(assigned(fErrors));

  result := fErrors.count;
End;


HTML generated by Time2HELP
http://www.time2help.com
errors method
Returns a list of the errors.

Applies to
TTestResult

Declaration
Function errors: TList;

Implementation

function TTestResult.errors: TList;
begin
  result := fErrors;
End;


HTML generated by Time2HELP
http://www.time2help.com
FailureCount method
Gets the number of detected failures.

Applies to
TTestResult

Declaration
Function FailureCount: integer;

Implementation

function TTestResult.FailureCount: integer;
begin
  assert(assigned(fFailures));

  result := fFailures.count;
End;


HTML generated by Time2HELP
http://www.time2help.com
Failures method
Returns a list of the failures.

Applies to
TTestResult

Declaration
Function Failures: TList;

Implementation

function TTestResult.Failures: TList;
begin
  result := fFailures;
End;


HTML generated by Time2HELP
http://www.time2help.com
Run method
Runs a TestCase.

Applies to
TTestResult

Declaration
Procedure Run(test: TTestCase);

Description
Run executes a test cases and broadcasts status informatio to any listeners registered with this TTestResult. Run also records any failures or errors that occur while running the testcase.

Implementation

procedure TTestResult.Run(test: TTestCase);
begin
  assert(assigned(test));
  if ShouldStop then
    EXIT;

  StartTest(test);
  try
    try
      test.SetUp;
    except
      on e: Exception do
      begin
        AddError(test, e, 'SetUp FAILED: ');
        EXIT;
      end
    end;
    try
      test.RunTest;
    except
      on e: EStopTestsFailure do
      begin
        AddFailure(test, e);
        FStop := True;
      end;
      on e: ETestFailure do
      begin
        AddFailure(test, e);
      end;
      on e: EBreakingTestFailure do
      begin
        AddFailure(test, e);
      end;
      on e: Exception do
      begin
        AddError(test, e);
      end;
    end;
    try
      test.TearDown;
    except
      on e: Exception do
        AddError(test, e, 'TearDown FAILED: ');
    end;
  finally
    EndTest(test);
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
RunCount method
Gets the number of run tests.

Applies to
TTestResult

Declaration
Function RunCount: integer;

Implementation

function TTestResult.RunCount: integer;
begin
  result := fRunTests;
End;


HTML generated by Time2HELP
http://www.time2help.com
RunSuite method
Runs a test.

Applies to
TTestResult

Declaration
Procedure RunSuite(test: TAbstractTest);

Description
Run executes a test cases and broadcasts status informatio to any listeners registered with this TTestResult. Run also records any failures or errors that occur while running the testcase. Listeners are also notified when TestingStarts and ends.

Parameters
test The test case to run.

Implementation

procedure TTestResult.RunSuite(test: TAbstractTest);
begin
  TestingStarts;
  try
    test.RunBare(self);
  finally
    TestingEnds
  end
End;


HTML generated by Time2HELP
http://www.time2help.com
ShouldStop method
Checks whether the test run should stop

Applies to
TTestResult

Declaration
Function ShouldStop: boolean;

Implementation

function TTestResult.ShouldStop: boolean;
begin
  result := fStop;
End;


HTML generated by Time2HELP
http://www.time2help.com
StartTest method
Informs the result that a test will be started.

Applies to
TTestResult

Declaration
Procedure StartTest(test: TTestCase);

Description
Notify any registered ITestListener that a test was started.

Implementation

procedure TTestResult.StartTest(test: TTestCase);
var
  i: integer;
begin
  assert(assigned(test));
  assert(assigned(fListeners));

  inc(fRunTests);
  for i := 0 to fListeners.count - 1 do
  begin
    (fListeners[i] as ITestListener).StartTest(test);
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
Stop method
Marks that the test run should stop.

Applies to
TTestResult

Declaration
Procedure Stop;

Implementation

procedure TTestResult.Stop;
begin
  fStop := true;
End;


HTML generated by Time2HELP
http://www.time2help.com
TestingEnds method
Notify listeners when testing ends

Applies to
TTestResult

Declaration
Procedure TestingEnds;

Implementation

procedure TTestResult.TestingEnds;
var
  i :Integer;
begin
  for i := 0 to fListeners.count - 1 do
  begin
    (fListeners[i] as ITestListener).TestingEnds(self);
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
TestingStarts method
Notify listeners when testing starts

Applies to
TTestResult

Declaration
Procedure TestingStarts;

Implementation

procedure TTestResult.TestingStarts;
var
  i :Integer;
begin
  for i := 0 to fListeners.count - 1 do
  begin
    (fListeners[i] as ITestListener).TestingStarts;
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
WasStopped method
Was testing stopped?.

Applies to
TTestResult

Declaration
Function WasStopped: boolean;

Implementation

function TTestResult.WasStopped: boolean;
begin
  result := fStop;
End;


HTML generated by Time2HELP
http://www.time2help.com
WasSuccessful method
Returns whether the entire test was successful or not.

Applies to
TTestResult

Declaration
Function WasSuccessful: boolean;

Implementation

function TTestResult.WasSuccessful: boolean;
begin
  result := (FailureCount = 0) and (ErrorCount() = 0) and not WasStopped;
End;


HTML generated by Time2HELP
http://www.time2help.com
TTestSuite Object
Methods
A TTestSuite is a Composite of Tests, implementing the ITestSuite interface.

Unit
TestFramework

Declaration
TTestSuite = class(TAbstractTest, ITest, ITestSuite)

Description
It runs a collection of test cases. It should not be necessary for test writers to extend TTestSuite. Decorators should be used instead. see TTestDecorator. see RegisterTest see ITest

Introduced Methods
AddSuite
AddTest
AddTests
CountEnabledTestCases
CountTestCases
Create  Constructs an empty TestSuite.
LoadConfiguration  Load a previously saved configuration.
RunBare
SaveConfiguration  Save the current test configuration.
Tests


HTML generated by Time2HELP
http://www.time2help.com
AddSuite method
Adds a test suite to the suite.

Applies to
TTestSuite

Declaration
Procedure AddSuite(suite : ITestSuite);

Parameters
suite The suite to add.

Implementation

procedure TTestSuite.AddSuite(suite: ITestSuite);
begin
  AddTest(suite);
End;


HTML generated by Time2HELP
http://www.time2help.com
AddTest method
Add a test to the suite.

Applies to
TTestSuite

Declaration
Procedure AddTest(ATest: ITest);

Parameters
ATest The test to add.

Implementation

procedure TTestSuite.AddTest(ATest: ITest);
begin
  Assert(Assigned(ATest));

  fTests.Add(ATest);
End;


HTML generated by Time2HELP
http://www.time2help.com
AddTests method
Makes a test instance out of each published method of the given testClass and adds them to the suite.

Applies to
TTestSuite

Declaration
Procedure AddTests(testClass: TTestCaseClass);

Parameters
testClass The testCase class with published test methods.

Implementation

procedure TTestSuite.AddTests(testClass: TTestCaseClass);
var
  MethodIter      : Integer;
  NameOfMethod    : string;
  MethodEnumerator : TMethodEnumerator;
begin
  { call on the method enumerator to get the names of the test
    cases in the testClass }
  MethodEnumerator := nil;
  try
    MethodEnumerator := TMethodEnumerator.Create(testClass);
    { make sure we add each test case  to the list of tests }
    for MethodIter := 0 to MethodEnumerator.Methodcount-1 do
      begin
        NameOfMethod := MethodEnumerator.nameOfMethod[MethodIter];
        self.addTest(testClass.Create(NameOfMethod) as ITest);
      end;
  finally
    MethodEnumerator.free;
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
CountEnabledTestCases method
Counts the number of enabled test cases in the suite and sub-suites.

Applies to
TTestSuite

Declaration
Function CountEnabledTestCases: integer;

Returns
The number of enabled test cases.

Implementation

function TTestSuite.CountEnabledTestCases: integer;
var
  i: Integer;
  test: ITest;
  Total : Integer;
begin
  assert(assigned(fTests));

  Total := 0;
  if getEnabled then
  begin
    for i := 0 to fTests.Count - 1 do
    begin
      test := fTests[i] as ITest;
      Total := Total + test.CountEnabledTestCases;
    end;
  end;
  Result := Total;
End;


HTML generated by Time2HELP
http://www.time2help.com
CountTestCases method
Counts the number of test cases in the suite and sub-suites.

Applies to
TTestSuite

Declaration
Function CountTestCases: integer;

Returns
The number of test cases.

Implementation

function TTestSuite.CountTestCases: integer;
var
  test: ITest;
  i: Integer;
  Total : integer;
begin
  assert(assigned(fTests));

  Total := 0;
  for i := 0 to fTests.Count - 1 do
  begin
    test := fTests[i] as ITest;
    Total := Total + test.CountTestCases;
  end;
  Result := Total;
End;


HTML generated by Time2HELP
http://www.time2help.com
Create method
Constructs an empty TestSuite.

Applies to
TTestSuite

Declaration
Constructor Create;

Description
Constructs an empty TestSuite with the same name as the class.

Implementation

constructor TTestSuite.Create;
begin
  self.Create(self.ClassName);
End;


HTML generated by Time2HELP
http://www.time2help.com
LoadConfiguration method
Load a previously saved configuration.

Applies to
TTestSuite

Declaration
Procedure LoadConfiguration(const iniFile :TIniFile; const section :string);

Description
The enabled/disabled state for each contained test will be read from the given TIniFile under the given section name.

Parameters
iniFile The TIniFile to read the configuration from.
section The name of the section the configuration will be read from.

Implementation

procedure TTestSuite.LoadConfiguration(const iniFile: TIniFile; const section :string);
var
  i     :integer;
  Tests :IInterfaceList;
begin
  inherited LoadConfiguration(iniFile, section);
  Tests := self.Tests;
  for i := 0 to Tests.count-1 do
    (Tests[i] as ITest).LoadConfiguration(iniFile, section + '.' + self.GetName);
End;


HTML generated by Time2HELP
http://www.time2help.com
RunBare method
Runs the tests in the suite.

Applies to
TTestSuite

Declaration
Procedure RunBare(testResult: TTestResult);

Parameters
TestResult Where to accumulate the test results.

See Also

Implementation

procedure TTestSuite.RunBare(testResult: TTestResult);
var
  i: Integer;
  test: ITest;
begin
  assert(assigned(testResult));
  assert(assigned(fTests));

  if getEnabled then
  begin
    for i := 0 to fTests.Count - 1 do
    begin
      if testResult.ShouldStop then
        BREAK;
      test := fTests[i] as ITest;
      test.RunBare(testResult);
    end;
  end;
End;


HTML generated by Time2HELP
http://www.time2help.com
SaveConfiguration method
Save the current test configuration.

Applies to
TTestSuite

Declaration
Procedure SaveConfiguration(const iniFile :TIniFile; const section :string);

Description
The enabled/disabled state of each contained test will be saved to the given TIniFile under the given section name.

Parameters
iniFile The TIniFile to save the configuration to.
section The name of the section the configuration will be saved to.

Implementation

procedure TTestSuite.SaveConfiguration(const iniFile: TIniFile; const section :string);
var
  i     :integer;
  Tests :IInterfaceList;
begin
  inherited SaveConfiguration(iniFile, section);
  Tests := self.Tests;
  for i := 0 to Tests.count-1 do
    (Tests[i] as ITest).SaveConfiguration(iniFile, section + '.' + self.GetName);
End;


HTML generated by Time2HELP
http://www.time2help.com
Tests method
Returns the list of tests contained in this suite

Applies to
TTestSuite

Declaration
Function Tests: IInterfaceList;

Returns
The contained list of tests, each of type ITest.

See Also

Implementation

function TTestSuite.Tests: IInterfaceList;
begin
  result := fTests;
End;


HTML generated by Time2HELP
http://www.time2help.com
ITest Interface
Properties Methods
ITest represents a test that can be run.

Unit
TestFramework

Declaration
ITest = interface(IUnknown)

Introduced Properties
Enabled Indicates if a test will be performed.
Name The name of this test.

Introduced Methods
CountEnabledTestCases Counts the number of test cases that will be run by this test.
CountTestCases Counts the number of test cases that can be run by this test.
GetEnabled returns true if the test is enabled to be run.
GetName Returns the name of this test.
LoadConfiguration Load a previously saved configuration.
Run A convenience method to run this test, collecting the results with a default TestResult object.
RunBare Runs a test and collects its result in a TTestResult instance.
SaveConfiguration Save the current test configuration.
SetEnabled Determine if this test will be run.
Tests


HTML generated by Time2HELP
http://www.time2help.com
Enabled Property
Indicates if a test will be performed.

Applies to
ITest

Declaration
Property Enabled : boolean Read GetEnabled Write SetEnabled;

Description
This test will only be run if enabled is true for this test.


HTML generated by Time2HELP
http://www.time2help.com
Name Property
The name of this test.

Applies to
ITest

Declaration
Property Name : string Read GetName;


HTML generated by Time2HELP
http://www.time2help.com
CountEnabledTestCases Method
Counts the number of test cases that will be run by this test.

Applies to
ITest

Declaration
Function CountEnabledTestCases: integer;


HTML generated by Time2HELP
http://www.time2help.com
CountTestCases Method
Counts the number of test cases that can be run by this test.

Applies to
ITest

Declaration
Function CountTestCases: integer;


HTML generated by Time2HELP
http://www.time2help.com
GetEnabled Method
returns true if the test is enabled to be run.

Applies to
ITest

Declaration
Function GetEnabled: boolean;


HTML generated by Time2HELP
http://www.time2help.com
GetName Method
Returns the name of this test.

Applies to
ITest

Declaration
Function GetName: string;


HTML generated by Time2HELP
http://www.time2help.com
LoadConfiguration Method
Load a previously saved configuration.

Applies to
ITest

Declaration
Procedure LoadConfiguration(const iniFile :TIniFile; const section :string);

Description
The enabled/disabled state for each contained test will be read from the given TIniFile under the given section name.

Parameters
iniFile The TIniFile to read the configuration from.
section The name of the section the configuration will be read from.


HTML generated by Time2HELP
http://www.time2help.com
Run Method
A convenience method to run this test, collecting the results with a default TestResult object.

Applies to
ITest

Declaration
Function Run: TTestResult;

Description
Run will Create a TTestResult, run this test case and collect any TTestFailure into the TTestResult. The caller is responsible for freeing the returned TTestResult.

Returns
A TTestResult with the results of running this test.


HTML generated by Time2HELP
http://www.time2help.com
RunBare Method
Runs a test and collects its result in a TTestResult instance.

Applies to
ITest

Declaration
Procedure RunBare(testResult: TTestResult);

Parameters
testResult the results of running this test are collected into this TTestResult object. see TTestResult


HTML generated by Time2HELP
http://www.time2help.com
SaveConfiguration Method
Save the current test configuration.

Applies to
ITest

Declaration
Procedure SaveConfiguration(const iniFile :TIniFile; const section :string);

Description
The enabled/disabled state of each contained test will be saved to the given TIniFile under the given section name.

Parameters
iniFile The TIniFile to save the configuration to.
section The name of the section the configuration will be saved to.


HTML generated by Time2HELP
http://www.time2help.com
SetEnabled Method
Determine if this test will be run.

Applies to
ITest

Declaration
Procedure SetEnabled(Value: boolean);

Parameters
value when true, the test will be enabled, when false, the test will be disabled.


HTML generated by Time2HELP
http://www.time2help.com
Tests Method

Applies to
ITest

Declaration
Function Tests: IInterfaceList;


HTML generated by Time2HELP
http://www.time2help.com
ITestListener Interface
Methods
A Listener for test progress.

Unit
TestFramework

Declaration
ITestListener = interface(IUnknown)

Description
TTestResult calls the methods of registered ITestListeners as testing progress. The standard TestRunners implement this interface to receive notifications about testing events.

Introduced Methods
AddError An error occurred.
AddFailure A failure occurred.
EndTest A test ended.
StartTest A test started.
TestingEnds Called when testing has ended.
TestingStarts Called when testing has started.

See Also


HTML generated by Time2HELP
http://www.time2help.com
AddError Method
An error occurred.

Applies to
ITestListener

Declaration
Procedure AddError(error: TTestFailure);


HTML generated by Time2HELP
http://www.time2help.com
AddFailure Method
A failure occurred.

Applies to
ITestListener

Declaration
Procedure AddFailure(Failure: TTestFailure);


HTML generated by Time2HELP
http://www.time2help.com
EndTest Method
A test ended.

Applies to
ITestListener

Declaration
Procedure EndTest(test: ITest);


HTML generated by Time2HELP
http://www.time2help.com
StartTest Method
A test started.

Applies to
ITestListener

Declaration
Procedure StartTest(test: ITest);


HTML generated by Time2HELP
http://www.time2help.com
TestingEnds Method
Called when testing has ended.

Applies to
ITestListener

Declaration
Procedure TestingEnds(testResult :TTestResult);


HTML generated by Time2HELP
http://www.time2help.com
TestingStarts Method
Called when testing has started.

Applies to
ITestListener

Declaration
Procedure TestingStarts;


HTML generated by Time2HELP
http://www.time2help.com
ITestSuite Interface
Methods
An ITestSuite is a Composite of Tests.

Unit
TestFramework

Declaration
ITestSuite = interface(ITest)

Description
It runs a collection of test cases as if they were a single test. see ITest

Introduced Methods
AddSuite
AddTest Adds a test to the suite.


HTML generated by Time2HELP
http://www.time2help.com
AddSuite Method

Applies to
ITestSuite

Declaration
Procedure AddSuite(suite : ITestSuite);


HTML generated by Time2HELP
http://www.time2help.com
AddTest Method
Adds a test to the suite.

Applies to
ITestSuite

Declaration
Procedure AddTest(test: ITest);


HTML generated by Time2HELP
http://www.time2help.com
CallerAddr Routine
Returns the address that the calling procedure will return to.

Unit
TestFramework

Declaration
Function CallerAddr: Pointer;

Description
Used internally by the framework. Don't use directly.

Implementation

function CallerAddr :Pointer; assembler;
const
  CallerIP = $4;
asm
   push  4
   push  ebp
   call  IsBadReadPtr
   test  eax,eax
   jne   @@Error

   mov   eax, [ebp].CallerIP
   sub   eax, 5   // 5 bytes for call

   push  eax
   push  4
   push  ebx
   call  IsBadReadPtr
   test  eax,eax
   pop   eax
   je    @@Finish

@@Error:
   xor eax, eax
@@Finish:
End;


HTML generated by Time2HELP
http://www.time2help.com
MakeTestSuite Routine
Create a named test suite out a series of tests

Unit
TestFramework

Declaration
Function MakeTestSuite(name :string; const Tests :array of ITest): ITestSuite;

Parameters
name The name the ITestSuite will have.
Tests The series of tests.

See Also




Use TTestSuite.Create(string, array of ITest) instead

Implementation

function  MakeTestSuite(name :string; const Tests :array of ITest): ITestSuite;
begin
   result := TTestSuite.Create(name, Tests);
End;


HTML generated by Time2HELP
http://www.time2help.com
MakeTestSuites Routine
Create a test suite hierarchy out of a series of TTestCase descendants

Unit
TestFramework

Declaration
Function MakeTestSuites(name :string; const classes :array of TTestCaseClass): ITestSuite;

Parameters
name The name the ITestSuite will have.
classes The series of TTestCase classes that will compose the suite.

See Also




Use TTestCase.Create(string, array of ITest) instead

Implementation

function  MakeTestSuites(name :string; const classes :array of TTestCaseClass): ITestSuite;
var
  i :Integer;
begin
   result := TTestSuite.Create(name);
   for i := Low(classes) to High(classes) do begin
      result.addTest(testSuiteOf(classes[i]));
   end;
End;


HTML generated by Time2HELP
http://www.time2help.com
RegisteredTests Routine
Return a TestSuite containing all registered tests.

Unit
TestFramework

Declaration
Function RegisteredTests: ITestSuite;

Returns
A TestSuite with all registered tests.

Implementation

function RegisteredTests: ITestSuite;
begin
  result := TheSuite;
End;


HTML generated by Time2HELP
http://www.time2help.com
RegisterTest Routine
Register a test.

Unit
TestFramework

Declaration
Procedure RegisterTest(SuitePath: string; test: ITest);

Description
Add a test to an arbitraty test suite in the test hierarchy. The SuitePath is a dot-separated list of suite names. The first name is taken to be a top level suite, the second a child of the first, and so on. Test suites are created if they don't exist. The test is added to the suite indicated by the last names.

Parameters
SuitePath Dot separated list of test suite names, indicating a path from the root of the test hierarchy. Tests are added to the suite indicated by the last name.
test The test to register.

Implementation

procedure RegisterTest(SuitePath: string; test: ITest);
begin
  assert(assigned(test));

  if not assigned(TheSuite) then
  begin
    TheSuite := TTestSuite.Create('Unit Tests');
  end;
  RegisterTestInSuite(TheSuite, SuitePath, test);
End;


HTML generated by Time2HELP
http://www.time2help.com
RegisterTests Routine
Register a series of tests under the given path.

Unit
TestFramework

Declaration
Procedure RegisterTests(SuitePath :string; const Tests :array of ITest);

Parameters
path Indicates a path of tests suites to register the test under.
Tests The series of tests to register.

Implementation

procedure RegisterTests(SuitePath :string; const Tests :array of ITest);
var
  i :Integer;
begin
  for i := Low(Tests) to High(Tests) do begin
    TestFramework.RegisterTest(SuitePath, Tests[i])
  end
End;


HTML generated by Time2HELP
http://www.time2help.com
RegisterTestSuites Routine
Register a series of test suites consisting of the published methods of the TTestCase descendants passed in the classes array.

Unit
TestFramework

Declaration
Procedure RegisterTestSuites(SuitePath :string; const classes :array of TTestCaseClass);

Parameters
path Indicates a path of tests suites to register the test under.
Tests The series of tests to register.

See Also




Use RegisterTest(string, array of ITest) instead, in combination with TTestCase.Suite, and TTestSuite.Create.

Implementation

procedure RegisterTestSuites(SuitePath :string; const classes :array of TTestCaseClass);
var
  i :Integer;
begin
  for i := Low(classes) to High(classes) do begin
    TestFramework.RegisterTest(SuitePath, classes[i])
  end
End;


HTML generated by Time2HELP
http://www.time2help.com
RunRegisteredTests Routine
Run registered tests using default features and notifying the given set of listeners of testing events.

Unit
TestFramework

Declaration
Function RunRegisteredTests(listeners :array of ITestListener): TTestResult;

Implementation

function RunRegisteredTests(listeners :array of ITestListener) :TTestResult;
begin
   result := RunTest(RegisteredTests, listeners)
End;


HTML generated by Time2HELP
http://www.time2help.com
RunTest Routine
Run a test using default features and notifying the given set of listeners of testing events.

Unit
TestFramework

Declaration
Function RunTest(suite :ITest; listeners :array of ITestListener): TTestResult;

Parameters
suite The test to run.

Implementation

function RunTest(suite :ITest; listeners :array of ITestListener) :TTestResult; overload;
var
  i         :Integer;
begin
    result := TTestResult.Create;
    for i := low(listeners) to high(listeners) do
        result.addListener(listeners[i]);
    suite.Run(result);
End;


HTML generated by Time2HELP
http://www.time2help.com
SetBreakOnFailures Routine
Allow the IDE to break on failure exceptions.

Unit
TestFramework

Declaration
Procedure SetBreakOnFailures(Enable :boolean);

Description
When set to True, the framework raises EEBreakingTestFailure when a test fails. The Delphi IDE will break on this type of exception by default. When set to False, the framework will raise ETestFailure instead, which is derived from EAbort, and on which the IDE will not brak by default. The default value is False.

Parameters
Enable True means enable IDE breaking on failure exceptions.

See Also

Implementation

procedure SetBreakOnFailures(Enable :boolean);
begin
  if Enable then
    __FailureExceptionClass := EBreakingTestFailure
  else
    __FailureExceptionClass := ETestFailure
End;


HTML generated by Time2HELP
http://www.time2help.com
TestSuiteOf Routine
Create a test suite out of the published methods in a TTestCase descendant

Unit
TestFramework

Declaration
Function TestSuiteOf(AClass: TTestCaseClass): ITestSuite;

Parameters
aclass The TTestCase class to get the test methods from.

See Also




Use TTestCase.Suite instead.

Implementation

function TestSuiteOf(AClass: TTestCaseClass): ITestSuite;
begin
  Result := TTestSuite.Create(AClass)
End;


HTML generated by Time2HELP
http://www.time2help.com
TTestCaseClass Type
Used to pass a class reference to a descendant of TTestCase to TTestSuite.Create.

Unit
TestFramework

Declaration

TTestCaseClass = class of TTestCase;


HTML generated by Time2HELP
http://www.time2help.com
TTestMethod Type
A method on a TTestCase descendent which implements a unit test.

Unit
TestFramework

Declaration

TTestMethod = procedure of object;


HTML generated by Time2HELP
http://www.time2help.com
rcs_id Global Constant
This is the version of the testframework which this documentation describes.

Unit
TestFramework

Declaration
rcs_id : string = '#(@)$Id: TestFramework.pas,v 1.36 2000/12/05 02:13:41 juanco Exp $';


HTML generated by Time2HELP
http://www.time2help.com