+ added test timing results to the test results from Graeme Geldenhuys

git-svn-id: trunk@4676 -
This commit is contained in:
Vincent Snijders 2006-09-21 18:40:24 +00:00
parent f671cc39e8
commit e1373d9d5f
2 changed files with 47 additions and 20 deletions

View File

@ -19,8 +19,9 @@ unit fpcunit;
interface interface
{$IFNDEF MORPHOS} {$IFNDEF MORPHOS}
{$DEFINE SHOWLINEINFO} {$DEFINE SHOWLINEINFO}
{$ENDIF} {$ENDIF}
{ Uncomment this define to remove the DUnit compatibility interface. } { Uncomment this define to remove the DUnit compatibility interface. }
{$DEFINE DUnit} {$DEFINE DUnit}
@ -225,13 +226,13 @@ type
{ TTestResult } { TTestResult }
TTestResult = class(TObject) TTestResult = class(TObject)
private
protected protected
FRunTests: integer; FRunTests: integer;
FFailures: TFPList; FFailures: TFPList;
FErrors: TFPList; FErrors: TFPList;
FListeners: TFPList; FListeners: TFPList;
FSkippedTests: TFPList; FSkippedTests: TFPList;
FStartingTime: TDateTime;
function GetNumErrors: integer; function GetNumErrors: integer;
function GetNumFailures: integer; function GetNumFailures: integer;
function GetNumSkipped: integer; function GetNumSkipped: integer;
@ -260,6 +261,7 @@ type
property NumberOfErrors: integer read GetNumErrors; property NumberOfErrors: integer read GetNumErrors;
property NumberOfFailures: integer read GetNumFailures; property NumberOfFailures: integer read GetNumFailures;
property NumberOfSkippedTests: integer read GetNumSkipped; property NumberOfSkippedTests: integer read GetNumSkipped;
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;
@ -976,10 +978,11 @@ end;
constructor TTestResult.Create; constructor TTestResult.Create;
begin begin
inherited Create; inherited Create;
FFailures := TFPList.Create; FFailures := TFPList.Create;
FErrors := TFPList.Create; FErrors := TFPList.Create;
FListeners := TFPList.Create; FListeners := TFPList.Create;
FSkippedTests := TFPList.Create; FSkippedTests := TFPList.Create;
FStartingTime := Now;
end; end;

View File

@ -52,6 +52,7 @@ type
FListing: TDOMNode; FListing: TDOMNode;
FFailures: TDOMNode; FFailures: TDOMNode;
FErrors: TDOMNode; FErrors: TDOMNode;
FStartCrono: TDateTime;
{ Converts the actual test results into XML nodes. This gets called { Converts the actual test results into XML nodes. This gets called
by the public method WriteResult. } by the public method WriteResult. }
procedure TestResultAsXML(pTestResult: TTestResult); procedure TestResultAsXML(pTestResult: TTestResult);
@ -95,18 +96,15 @@ begin
n := FDoc.CreateElement('NumberOfFailures'); n := FDoc.CreateElement('NumberOfFailures');
n.AppendChild(FDoc.CreateTextNode(IntToStr(pTestResult.NumberOfFailures))); n.AppendChild(FDoc.CreateTextNode(IntToStr(pTestResult.NumberOfFailures)));
lResults.AppendChild(n); lResults.AppendChild(n);
if pTestResult.NumberOfErrors <> 0 then
begin
for i := 0 to pTestResult.Errors.Count - 1 do
AddError(nil, TTestFailure(pTestResult.Errors.Items[i]));
end;
if pTestResult.NumberOfFailures <> 0 then n := FDoc.CreateElement('TotalElapsedTime');
begin n.AppendChild(FDoc.CreateTextNode(FormatDateTime('hh:nn:ss.zzz', Now - pTestResult.StartingTime)));
for i := 0 to pTestResult.Failures.Count - 1 do lResults.AppendChild(n);
AddFailure(nil, TTestFailure(pTestResult.Failures.Items[i]));
end; { Summary of ISO 8601 http://www.cl.cam.ac.uk/~mgk25/iso-time.html }
n := FDoc.CreateElement('DateTimeRan');
n.AppendChild(FDoc.CreateTextNode(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now)));
lResults.AppendChild(n);
end; end;
@ -114,7 +112,7 @@ procedure TXMLResultsWriter.WriteHeader;
begin begin
FResults := FDoc.CreateElement('TestResults'); FResults := FDoc.CreateElement('TestResults');
FResults.AppendChild(FDoc.CreateComment(' Generated using FPCUnit on ' FResults.AppendChild(FDoc.CreateComment(' Generated using FPCUnit on '
+ FormatDateTime('yyyy-mm-dd hh:mm ', Now) )); + FormatDateTime('yyyy-mm-dd hh:mm:ss', Now) ));
FDoc.AppendChild(FResults); FDoc.AppendChild(FResults);
FListing := FDoc.CreateElement('TestListing'); FListing := FDoc.CreateElement('TestListing');
FResults.AppendChild(FListing); FResults.AppendChild(FListing);
@ -127,6 +125,7 @@ begin
FResults := nil; FResults := nil;
FFailures := nil; FFailures := nil;
FErrors := nil; FErrors := nil;
FListing := nil;
WriteHeader; WriteHeader;
end; end;
@ -195,17 +194,42 @@ procedure TXMLResultsWriter.StartTest(ATest: TTest);
var var
n: TDOMElement; n: TDOMElement;
begin begin
{ Try and find the Listings node first }
if not Assigned(FListing) then if not Assigned(FListing) then
exit; FListing := FDoc.FindNode('TestListing');
{ If we couldn't find it, create it }
if not Assigned(FListing) then
begin
FListing := FDoc.CreateElement('TestListing');
FResults.AppendChild(FListing);
end;
n := FDoc.CreateElement('Test'); n := FDoc.CreateElement('Test');
n['Name'] := ATest.TestSuiteName + '.' + ATest.TestName; n['Name'] := ATest.TestSuiteName + '.' + ATest.TestName;
FListing.AppendChild(n); FListing.AppendChild(n);
FStartCrono := Now;
end; end;
procedure TXMLResultsWriter.EndTest(ATest: TTest); procedure TXMLResultsWriter.EndTest(ATest: TTest);
var
n: TDOMNode;
lNew: TDOMElement;
begin begin
{ do nothing } { Try and find the Listings node first }
if not Assigned(FListing) then
FListing := FDoc.FindNode('TestListing');
{ If we couldn't find it, create it }
if not Assigned(FListing) then
begin
FListing := FDoc.CreateElement('TestListing');
FResults.AppendChild(FListing);
end;
n := FListing.LastChild;
lNew := FDoc.CreateElement('ElapsedTime');
lNew.AppendChild(FDoc.CreateTextNode(FormatDateTime('hh:nn:ss.zzz', Now - FStartCrono)));
n.AppendChild(lNew);
end; end;