|
@@ -47,6 +47,10 @@ type
|
|
constructor Create(const msg :string); overload;
|
|
constructor Create(const msg :string); overload;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ EIgnoredTest = class(EAssertionFailedError);
|
|
|
|
+
|
|
|
|
+
|
|
TTestStep = (stSetUp, stRunTest, stTearDown, stNothing);
|
|
TTestStep = (stSetUp, stRunTest, stTearDown, stNothing);
|
|
|
|
|
|
|
|
|
|
@@ -60,14 +64,18 @@ type
|
|
FLastStep: TTestStep;
|
|
FLastStep: TTestStep;
|
|
function GetTestName: string; virtual;
|
|
function GetTestName: string; virtual;
|
|
function GetTestSuiteName: string; virtual;
|
|
function GetTestSuiteName: string; virtual;
|
|
|
|
+ function GetEnableIgnores: boolean; virtual;
|
|
procedure SetTestSuiteName(const aName: string); virtual; abstract;
|
|
procedure SetTestSuiteName(const aName: string); virtual; abstract;
|
|
|
|
+ procedure SetEnableIgnores(Value: boolean); virtual; abstract;
|
|
public
|
|
public
|
|
function CountTestCases: integer; virtual;
|
|
function CountTestCases: integer; virtual;
|
|
procedure Run(AResult: TTestResult); virtual;
|
|
procedure Run(AResult: TTestResult); virtual;
|
|
|
|
+ procedure Ignore(const AMessage: string);
|
|
published
|
|
published
|
|
property TestName: string read GetTestName;
|
|
property TestName: string read GetTestName;
|
|
property TestSuiteName: string read GetTestSuiteName write SetTestSuiteName;
|
|
property TestSuiteName: string read GetTestSuiteName write SetTestSuiteName;
|
|
property LastStep: TTestStep read FLastStep;
|
|
property LastStep: TTestStep read FLastStep;
|
|
|
|
+ property EnableIgnores: boolean read GetEnableIgnores write SetEnableIgnores;
|
|
end;
|
|
end;
|
|
{$M-}
|
|
{$M-}
|
|
|
|
|
|
@@ -138,6 +146,7 @@ type
|
|
function GetAsString: string;
|
|
function GetAsString: string;
|
|
function GetExceptionMessage: string;
|
|
function GetExceptionMessage: string;
|
|
function GetIsFailure: boolean;
|
|
function GetIsFailure: boolean;
|
|
|
|
+ function GetIsIgnoredTest: boolean;
|
|
function GetExceptionClassName: string;
|
|
function GetExceptionClassName: string;
|
|
procedure SetTestLastStep(const Value: TTestStep);
|
|
procedure SetTestLastStep(const Value: TTestStep);
|
|
public
|
|
public
|
|
@@ -146,6 +155,7 @@ type
|
|
published
|
|
published
|
|
property AsString: string read GetAsString;
|
|
property AsString: string read GetAsString;
|
|
property IsFailure: boolean read GetIsFailure;
|
|
property IsFailure: boolean read GetIsFailure;
|
|
|
|
+ property IsIgnoredTest: boolean read GetIsIgnoredTest;
|
|
property ExceptionMessage: string read GetExceptionMessage;
|
|
property ExceptionMessage: string read GetExceptionMessage;
|
|
property ExceptionClassName: string read GetExceptionClassName;
|
|
property ExceptionClassName: string read GetExceptionClassName;
|
|
property SourceUnitName: string read FSourceUnitName write FSourceUnitName;
|
|
property SourceUnitName: string read FSourceUnitName write FSourceUnitName;
|
|
@@ -166,6 +176,7 @@ type
|
|
private
|
|
private
|
|
FName: string;
|
|
FName: string;
|
|
FTestSuiteName: string;
|
|
FTestSuiteName: string;
|
|
|
|
+ FEnableIgnores: boolean;
|
|
protected
|
|
protected
|
|
function CreateResult: TTestResult; virtual;
|
|
function CreateResult: TTestResult; virtual;
|
|
procedure SetUp; virtual;
|
|
procedure SetUp; virtual;
|
|
@@ -173,8 +184,10 @@ type
|
|
procedure RunTest; virtual;
|
|
procedure RunTest; virtual;
|
|
function GetTestName: string; override;
|
|
function GetTestName: string; override;
|
|
function GetTestSuiteName: string; override;
|
|
function GetTestSuiteName: string; override;
|
|
|
|
+ function GetEnableIgnores: boolean; override;
|
|
procedure SetTestSuiteName(const aName: string); override;
|
|
procedure SetTestSuiteName(const aName: string); override;
|
|
procedure SetTestName(const Value: string); virtual;
|
|
procedure SetTestName(const Value: string); virtual;
|
|
|
|
+ procedure SetEnableIgnores(Value: boolean); override;
|
|
procedure RunBare; virtual;
|
|
procedure RunBare; virtual;
|
|
public
|
|
public
|
|
constructor Create; virtual;
|
|
constructor Create; virtual;
|
|
@@ -196,12 +209,15 @@ type
|
|
FTests: TFPList;
|
|
FTests: TFPList;
|
|
FName: string;
|
|
FName: string;
|
|
FTestSuiteName: string;
|
|
FTestSuiteName: string;
|
|
|
|
+ FEnableIgnores: boolean;
|
|
function GetTest(Index: integer): TTest;
|
|
function GetTest(Index: integer): TTest;
|
|
protected
|
|
protected
|
|
function GetTestName: string; override;
|
|
function GetTestName: string; override;
|
|
function GetTestSuiteName: string; override;
|
|
function GetTestSuiteName: string; override;
|
|
|
|
+ function GetEnableIgnores: boolean; override;
|
|
procedure SetTestSuiteName(const aName: string); override;
|
|
procedure SetTestSuiteName(const aName: string); override;
|
|
procedure SetTestName(const Value: string); virtual;
|
|
procedure SetTestName(const Value: string); virtual;
|
|
|
|
+ procedure SetEnableIgnores(Value: boolean); override;
|
|
public
|
|
public
|
|
constructor Create(AClass: TClass; AName: string); reintroduce; overload; virtual;
|
|
constructor Create(AClass: TClass; AName: string); reintroduce; overload; virtual;
|
|
constructor Create(AClass: TClass); reintroduce; overload; virtual;
|
|
constructor Create(AClass: TClass); reintroduce; overload; virtual;
|
|
@@ -229,20 +245,21 @@ type
|
|
protected
|
|
protected
|
|
FRunTests: integer;
|
|
FRunTests: integer;
|
|
FFailures: TFPList;
|
|
FFailures: TFPList;
|
|
|
|
+ FIgnoredTests: TFPList;
|
|
FErrors: TFPList;
|
|
FErrors: TFPList;
|
|
FListeners: TFPList;
|
|
FListeners: TFPList;
|
|
FSkippedTests: TFPList;
|
|
FSkippedTests: TFPList;
|
|
FStartingTime: TDateTime;
|
|
FStartingTime: TDateTime;
|
|
function GetNumErrors: integer;
|
|
function GetNumErrors: integer;
|
|
function GetNumFailures: integer;
|
|
function GetNumFailures: integer;
|
|
|
|
+ function GetNumIgnoredTests: integer;
|
|
function GetNumSkipped: integer;
|
|
function GetNumSkipped: integer;
|
|
public
|
|
public
|
|
constructor Create; virtual;
|
|
constructor Create; virtual;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
- property Listeners: TFPList read FListeners;
|
|
|
|
procedure ClearErrorLists;
|
|
procedure ClearErrorLists;
|
|
procedure StartTest(ATest: TTest);
|
|
procedure StartTest(ATest: TTest);
|
|
- procedure AddFailure(ATest: TTest; E: EAssertionFailedError);
|
|
|
|
|
|
+ procedure AddFailure(ATest: TTest; E: EAssertionFailedError; aFailureList: TFPList);
|
|
procedure AddError(ATest: TTest; E: Exception; AUnitName: string;
|
|
procedure AddError(ATest: TTest; E: Exception; AUnitName: string;
|
|
AFailedMethodName: string; ALineNumber: longint);
|
|
AFailedMethodName: string; ALineNumber: longint);
|
|
procedure EndTest(ATest: TTest);
|
|
procedure EndTest(ATest: TTest);
|
|
@@ -255,17 +272,21 @@ type
|
|
procedure AddToSkipList(ATestCase: TTestCase);
|
|
procedure AddToSkipList(ATestCase: TTestCase);
|
|
procedure RemoveFromSkipList(ATestCase: TTestCase);
|
|
procedure RemoveFromSkipList(ATestCase: TTestCase);
|
|
published
|
|
published
|
|
|
|
+ property Listeners: TFPList read FListeners;
|
|
property Failures: TFPList read FFailures;
|
|
property Failures: TFPList read FFailures;
|
|
|
|
+ property IgnoredTests: TFPList read FIgnoredTests;
|
|
property Errors: TFPList read FErrors;
|
|
property Errors: TFPList read FErrors;
|
|
property RunTests: integer read FRunTests;
|
|
property RunTests: integer read FRunTests;
|
|
property NumberOfErrors: integer read GetNumErrors;
|
|
property NumberOfErrors: integer read GetNumErrors;
|
|
property NumberOfFailures: integer read GetNumFailures;
|
|
property NumberOfFailures: integer read GetNumFailures;
|
|
|
|
+ property NumberOfIgnoredTests: integer read GetNumIgnoredTests;
|
|
property NumberOfSkippedTests: integer read GetNumSkipped;
|
|
property NumberOfSkippedTests: integer read GetNumSkipped;
|
|
property StartingTime: TDateTime read FStartingTime;
|
|
property StartingTime: TDateTime read FStartingTime;
|
|
end;
|
|
end;
|
|
|
|
|
|
function ComparisonMsg(const aExpected: string; const aActual: string): string;
|
|
function ComparisonMsg(const aExpected: string; const aActual: string): string;
|
|
|
|
|
|
|
|
+
|
|
Resourcestring
|
|
Resourcestring
|
|
|
|
|
|
SCompare = ' expected: <%s> but was: <%s>';
|
|
SCompare = ' expected: <%s> but was: <%s>';
|
|
@@ -366,6 +387,10 @@ begin
|
|
Result := FRaisedExceptionClass.InheritsFrom(EAssertionFailedError);
|
|
Result := FRaisedExceptionClass.InheritsFrom(EAssertionFailedError);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TTestFailure.GetIsIgnoredTest: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result := FRaisedExceptionClass.InheritsFrom(EIgnoredTest);
|
|
|
|
+end;
|
|
|
|
|
|
procedure TTestFailure.SetTestLastStep(const Value: TTestStep);
|
|
procedure TTestFailure.SetTestLastStep(const Value: TTestStep);
|
|
begin
|
|
begin
|
|
@@ -392,12 +417,20 @@ begin
|
|
Result := 0;
|
|
Result := 0;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TTest.GetEnableIgnores: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result := True;
|
|
|
|
+end;
|
|
|
|
|
|
procedure TTest.Run(AResult: TTestResult);
|
|
procedure TTest.Run(AResult: TTestResult);
|
|
begin
|
|
begin
|
|
{ do nothing }
|
|
{ do nothing }
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTest.Ignore(const AMessage: String);
|
|
|
|
+begin
|
|
|
|
+ if EnableIgnores then raise EIgnoredTest.Create(AMessage);
|
|
|
|
+end;
|
|
|
|
|
|
{ TAssert }
|
|
{ TAssert }
|
|
|
|
|
|
@@ -702,6 +735,7 @@ end;
|
|
constructor TTestCase.Create;
|
|
constructor TTestCase.Create;
|
|
begin
|
|
begin
|
|
inherited Create;
|
|
inherited Create;
|
|
|
|
+ FEnableIgnores := True;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -744,6 +778,12 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
+function TTestCase.GetEnableIgnores: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result := FEnableIgnores;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
function TTestCase.GetTestSuiteName: string;
|
|
function TTestCase.GetTestSuiteName: string;
|
|
begin
|
|
begin
|
|
Result := FTestSuiteName;
|
|
Result := FTestSuiteName;
|
|
@@ -763,6 +803,12 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
+procedure TTestCase.SetEnableIgnores(Value: boolean);
|
|
|
|
+begin
|
|
|
|
+ FEnableIgnores := Value;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
function TTestCase.CreateResultAndRun: TTestResult;
|
|
function TTestCase.CreateResultAndRun: TTestResult;
|
|
begin
|
|
begin
|
|
Result := CreateResult;
|
|
Result := CreateResult;
|
|
@@ -797,7 +843,7 @@ var
|
|
RunMethod: TRunMethod;
|
|
RunMethod: TRunMethod;
|
|
pMethod : Pointer;
|
|
pMethod : Pointer;
|
|
begin
|
|
begin
|
|
- AssertNotNull(FName);
|
|
|
|
|
|
+ AssertNotNull('name of the test not assigned', FName);
|
|
pMethod := Self.MethodAddress(FName);
|
|
pMethod := Self.MethodAddress(FName);
|
|
if (Assigned(pMethod)) then
|
|
if (Assigned(pMethod)) then
|
|
begin
|
|
begin
|
|
@@ -882,6 +928,7 @@ constructor TTestSuite.Create;
|
|
begin
|
|
begin
|
|
inherited Create;
|
|
inherited Create;
|
|
FTests := TFPList.Create;
|
|
FTests := TFPList.Create;
|
|
|
|
+ FEnableIgnores := True;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -911,6 +958,12 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
+function TTestSuite.GetEnableIgnores: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result := FEnableIgnores;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
procedure TTestSuite.SetTestName(const Value: string);
|
|
procedure TTestSuite.SetTestName(const Value: string);
|
|
begin
|
|
begin
|
|
FName := Value;
|
|
FName := Value;
|
|
@@ -924,6 +977,18 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
+procedure TTestSuite.SetEnableIgnores(Value: boolean);
|
|
|
|
+var
|
|
|
|
+ i: integer;
|
|
|
|
+begin
|
|
|
|
+ if FEnableIgnores <> Value then
|
|
|
|
+ begin
|
|
|
|
+ FEnableIgnores := Value;
|
|
|
|
+ for i := 0 to FTests.Count - 1 do
|
|
|
|
+ TTest(FTests[i]).EnableIgnores := Value;
|
|
|
|
+ end
|
|
|
|
+end;
|
|
|
|
+
|
|
function TTestSuite.CountTestCases: integer;
|
|
function TTestSuite.CountTestCases: integer;
|
|
var
|
|
var
|
|
i: integer;
|
|
i: integer;
|
|
@@ -979,6 +1044,7 @@ constructor TTestResult.Create;
|
|
begin
|
|
begin
|
|
inherited Create;
|
|
inherited Create;
|
|
FFailures := TFPList.Create;
|
|
FFailures := TFPList.Create;
|
|
|
|
+ FIgnoredTests := TFPList.Create;
|
|
FErrors := TFPList.Create;
|
|
FErrors := TFPList.Create;
|
|
FListeners := TFPList.Create;
|
|
FListeners := TFPList.Create;
|
|
FSkippedTests := TFPList.Create;
|
|
FSkippedTests := TFPList.Create;
|
|
@@ -990,6 +1056,8 @@ destructor TTestResult.Destroy;
|
|
begin
|
|
begin
|
|
FreeObjects(FFailures);
|
|
FreeObjects(FFailures);
|
|
FFailures.Free;
|
|
FFailures.Free;
|
|
|
|
+ FreeObjects(FIgnoredTests);
|
|
|
|
+ FIgnoredTests.Free;
|
|
FreeObjects(FErrors);
|
|
FreeObjects(FErrors);
|
|
FErrors.Free;
|
|
FErrors.Free;
|
|
FListeners.Free;
|
|
FListeners.Free;
|
|
@@ -1001,6 +1069,8 @@ procedure TTestResult.ClearErrorLists;
|
|
begin
|
|
begin
|
|
FreeObjects(FFailures);
|
|
FreeObjects(FFailures);
|
|
FFailures.Clear;
|
|
FFailures.Clear;
|
|
|
|
+ FreeObjects(FIgnoredTests);
|
|
|
|
+ FIgnoredTests.Clear;
|
|
FreeObjects(FErrors);
|
|
FreeObjects(FErrors);
|
|
FErrors.Clear;
|
|
FErrors.Clear;
|
|
end;
|
|
end;
|
|
@@ -1017,6 +1087,10 @@ begin
|
|
Result := FFailures.Count;
|
|
Result := FFailures.Count;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TTestResult.GetNumIgnoredTests: integer;
|
|
|
|
+begin
|
|
|
|
+ Result := FIgnoredTests.Count;
|
|
|
|
+end;
|
|
|
|
|
|
function TTestResult.GetNumSkipped: integer;
|
|
function TTestResult.GetNumSkipped: integer;
|
|
begin
|
|
begin
|
|
@@ -1036,14 +1110,14 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-procedure TTestResult.AddFailure(ATest: TTest; E: EAssertionFailedError);
|
|
|
|
|
|
+procedure TTestResult.AddFailure(ATest: TTest; E: EAssertionFailedError; aFailureList: TFPList);
|
|
var
|
|
var
|
|
i: integer;
|
|
i: integer;
|
|
f: TTestFailure;
|
|
f: TTestFailure;
|
|
begin
|
|
begin
|
|
//lock mutex
|
|
//lock mutex
|
|
f := TTestFailure.CreateFailure(ATest, E, ATest.LastStep);
|
|
f := TTestFailure.CreateFailure(ATest, E, ATest.LastStep);
|
|
- FFailures.Add(f);
|
|
|
|
|
|
+ aFailureList.Add(f);
|
|
for i := 0 to FListeners.Count - 1 do
|
|
for i := 0 to FListeners.Count - 1 do
|
|
ITestListener(FListeners[i]).AddFailure(ATest, f);
|
|
ITestListener(FListeners[i]).AddFailure(ATest, f);
|
|
//unlock mutex
|
|
//unlock mutex
|
|
@@ -1105,8 +1179,10 @@ begin
|
|
try
|
|
try
|
|
protect(ATestCase, Self);
|
|
protect(ATestCase, Self);
|
|
except
|
|
except
|
|
|
|
+ on E: EIgnoredTest do
|
|
|
|
+ AddFailure(ATestCase, E, FIgnoredTests);
|
|
on E: EAssertionFailedError do
|
|
on E: EAssertionFailedError do
|
|
- AddFailure(ATestCase, E);
|
|
|
|
|
|
+ AddFailure(ATestCase, E, FFailures);
|
|
on E: Exception do
|
|
on E: Exception do
|
|
begin
|
|
begin
|
|
{$ifdef SHOWLINEINFO}
|
|
{$ifdef SHOWLINEINFO}
|