1
{ This is a template generated by Lazarus -> New Project -> FPCUnit Console
2
test runner, reworked by Kambi to fit into a reusable unit. }
3
unit ConsoleTestRunner;
10
custapp, classes, sysutils, fpcunit, testreport, testregistry,
14
TTestRunner = Class(TCustomApplication)
16
FPlainResultsWriter: TPlainResultsWriter;
18
procedure DoRun ; Override;
19
procedure doTestRun(aTest: TTest); virtual;
21
constructor Create(AOwner: TComponent); override;
22
destructor Destroy; override;
26
{ Use this to run your tests.
27
Just call Application.Initialize, then Application.Run.
28
This is created/destroyed in initialization/finalization
30
Application : TTestRunner;
36
Longopts : Array[1..5] of String = (
37
'all','list','format:','suite:','help');
38
Version = 'Version 0.1';
40
constructor TTestRunner.Create(AOwner: TComponent);
42
inherited Create(AOwner);
43
FPlainResultsWriter := TPlainResultsWriter.Create;
46
destructor TTestRunner.Destroy;
48
FPlainResultsWriter.Free;
51
procedure TTestRunner.doTestRun(aTest: TTest);
53
testResult: TTestResult;
55
testResult := TTestResult.Create;
57
testResult.AddListener(FPlainResultsWriter);
58
aTest.Run(testResult);
59
FPlainResultsWriter.WriteResult(testResult);
65
procedure TTestRunner.DoRun;
71
S:=CheckOptions(ShortOpts,LongOpts);
74
if HasOption('h', 'help') or (ParamCount = 0) then
79
writeln('-l or --list to show a list of registered tests');
80
writeln('default format is xml, add --format=latex to output the list as latex source');
81
writeln('-a or --all to run all the tests and show the results in xml format');
82
writeln('The results can be redirected to an xml file,');
83
writeln('for example: ./testrunner --all > results.xml');
84
writeln('use --suite=MyTestSuiteName to run only the tests in a single test suite class');
86
if HasOption('l', 'list') then
88
if HasOption('format') then
90
if GetOptionValue('format') = 'latex' then
91
writeln(GetSuiteAsLatex(GetTestRegistry))
93
writeln(GetSuiteAsXML(GetTestRegistry));
96
writeln(GetSuiteAsXML(GetTestRegistry));
98
if HasOption('a', 'all') then
100
doTestRun(GetTestRegistry)
103
if HasOption('suite') then
106
S:=GetOptionValue('suite');
108
for I := 0 to GetTestRegistry.Tests.count - 1 do
109
writeln(GetTestRegistry[i].TestName)
113
for I := 0 to GetTestRegistry.Tests.count - 1 do
114
if GetTestRegistry[i].TestName = S then
117
doTestRun(GetTestRegistry[i]);
119
if not SuiteFound then
120
Writeln('Suite name "', S, '" not found');
127
Application:=TTestRunner.Create(Nil);
128
Application.Title := 'FPCUnit Console Test Case runner.';
130
FreeAndNil(Application);
b'\\ No newline at end of file'