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

View File

@ -52,6 +52,7 @@ type
FListing: TDOMNode;
FFailures: TDOMNode;
FErrors: TDOMNode;
FStartCrono: TDateTime;
{ Converts the actual test results into XML nodes. This gets called
by the public method WriteResult. }
procedure TestResultAsXML(pTestResult: TTestResult);
@ -95,18 +96,15 @@ begin
n := FDoc.CreateElement('NumberOfFailures');
n.AppendChild(FDoc.CreateTextNode(IntToStr(pTestResult.NumberOfFailures)));
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
begin
for i := 0 to pTestResult.Failures.Count - 1 do
AddFailure(nil, TTestFailure(pTestResult.Failures.Items[i]));
end;
n := FDoc.CreateElement('TotalElapsedTime');
n.AppendChild(FDoc.CreateTextNode(FormatDateTime('hh:nn:ss.zzz', Now - pTestResult.StartingTime)));
lResults.AppendChild(n);
{ 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;
@ -114,7 +112,7 @@ procedure TXMLResultsWriter.WriteHeader;
begin
FResults := FDoc.CreateElement('TestResults');
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);
FListing := FDoc.CreateElement('TestListing');
FResults.AppendChild(FListing);
@ -127,6 +125,7 @@ begin
FResults := nil;
FFailures := nil;
FErrors := nil;
FListing := nil;
WriteHeader;
end;
@ -195,17 +194,42 @@ procedure TXMLResultsWriter.StartTest(ATest: TTest);
var
n: TDOMElement;
begin
{ Try and find the Listings node first }
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['Name'] := ATest.TestSuiteName + '.' + ATest.TestName;
FListing.AppendChild(n);
FStartCrono := Now;
end;
procedure TXMLResultsWriter.EndTest(ATest: TTest);
var
n: TDOMNode;
lNew: TDOMElement;
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;