-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuTestDB1.pas
executable file
·191 lines (156 loc) · 3.62 KB
/
uTestDB1.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
unit uTestDB1;
interface
uses
Classes,
TestFramework, TestExtensions;
type
TTestDBSetup = class(TTestSetup, ITestSuite)
protected
function CountTestsInterfaces: Integer;
function CountEnabledTestInterfaces: Integer;
public
procedure SetUp; override;
procedure TearDown; override;
function CountTestCases: Integer; override;
function CountEnabledTestCases: Integer; override;
function GetName: string; override;
procedure RunTest(ATestResult: TTestResult); override;
procedure AddTest(test: ITest);
procedure AddSuite(suite : ITestSuite);
published
// this method is not executed (for TTestSetup)
procedure TestDBSetupTest;
end;
TTestDB1 = class(TTestCase)
public
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestDB1_1;
procedure TestDB1_2;
end;
TTestDB2 = class(TTestCase)
public
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestDB2_1;
procedure TestDB2_2;
end;
implementation
uses
SysUtils,
uTestedDBClass;
{ TTestDB1 }
procedure TTestDB1.SetUp;
begin
inherited;
CheckTrue(TDBConnection.Connected, 'Not connected to DB!');
end;
procedure TTestDB1.TearDown;
begin
inherited;
end;
procedure TTestDB1.TestDB1_1;
begin
CheckTrue(True);
end;
procedure TTestDB1.TestDB1_2;
begin
CheckTrue(True);
end;
{ TTestDBSetup }
procedure TTestDBSetup.TestDBSetupTest;
begin
CheckTrue(True);
end;
procedure TTestDBSetup.AddSuite(suite: ITestSuite);
begin
AddTest(suite);
end;
procedure TTestDBSetup.AddTest(test: ITest);
begin
Assert(Assigned(test));
FTests.Add(test);
end;
function TTestDBSetup.CountEnabledTestCases: Integer;
begin
Result := inherited CountEnabledTestCases;
if Enabled then
Inc(Result, CountEnabledTestInterfaces);
end;
function TTestDBSetup.CountEnabledTestInterfaces: Integer;
var
i: Integer;
begin
Result := 0;
// skip FIRST test case (it is FTest)
for i := 1 to FTests.Count - 1 do
if (FTests[i] as ITest).Enabled then
Inc(Result, (FTests[i] as ITest).CountEnabledTestCases);
end;
function TTestDBSetup.CountTestCases: Integer;
begin
Result := inherited CountTestCases;
if Enabled then
Inc(Result, CountTestsInterfaces);
end;
function TTestDBSetup.CountTestsInterfaces: Integer;
var
i: Integer;
begin
Result := 0;
// skip FIRST test case (it is FTest)
for i := 1 to FTests.Count - 1 do
Inc(Result, (FTests[i] as ITest).CountTestCases);
end;
function TTestDBSetup.GetName: string;
begin
Result := FTestName;
end;
procedure TTestDBSetup.RunTest(ATestResult: TTestResult);
var
i: Integer;
begin
inherited;
// skip FIRST test case (it is FTest)
for i := 1 to FTests.Count - 1 do
(FTests[i] as ITest).RunWithFixture(ATestResult);
end;
procedure TTestDBSetup.SetUp;
begin
inherited;
TDBConnection.Connect;
end;
procedure TTestDBSetup.TearDown;
begin
TDBConnection.Disconnect;
inherited;
end;
{ TTestDB2 }
procedure TTestDB2.SetUp;
begin
inherited;
CheckTrue(TDBConnection.Connected, 'Not connected to DB!');
end;
procedure TTestDB2.TearDown;
begin
inherited;
end;
procedure TTestDB2.TestDB2_1;
begin
CheckTrue(True);
end;
procedure TTestDB2.TestDB2_2;
begin
CheckTrue(True);
end;
function DBSuite: ITestSuite;
begin
Result := TTestSuite.Create('DB tests');
Result.AddTest(TTestDB1.Suite);
Result.AddTest(TTestDB2.Suite);
end;
initialization
RegisterTest(TTestDBSetup.Create(DBSuite, 'DB'));
end.