forked from HCL-TECH-SOFTWARE/voltscript-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleBeforeAfterTester.bss
176 lines (133 loc) · 4.35 KB
/
SampleBeforeAfterTester.bss
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
%REM
Copyright 2022-2023 HCL America, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License
%END REM
%REM
Agent SampleBeforeAfterTester
Created Mar 17, 2022 by Paul Withers/UK/PNPHCL
Description: Tests custom before/after code and final test uses custom tester
%END REM
Option Public
Option Declare
Use "./src/VoltScriptTesting"
Private a As Integer
Private b As Integer
%REM
Copyright 2022 Paul Withers
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License
%END REM
%REM
CustomBeforeAfter to set up integers before the start of the test,
increment a before each test, increment b after each test and msgbox both after all tests
%END REM
Class IntegerIncrementBeforeAfter As AbstractCustomBeforeAfter
%REM
Sub beforeAll
Description: Set a and b to zero
%END REM
Sub beforeAll()
a = 0
b = 0
End Sub
%REM
Sub beforeEach
Description: Increment a
%END REM
Sub beforeEach()
a = a + 1
End Sub
%REM
Sub afterEach
Description: Increment b
%END REM
Sub afterEach()
b = b + 1
End Sub
%REM
Sub afterAll
Description: Print both a and b
%END REM
Sub afterAll()
Print |a is | & a & |, b is | & b
End Sub
End Class
%REM
Copyright 2022 Paul Withers
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License
%END REM
%REM
Class CustomTesterOneLess
Description: Custom tester to test a > b
%END REM
Class CustomTesterGreaterThan As AbstractCustomTester
%REM
Function runTests
Description: One test, testing a > b
%END REM
Function runTests() As Boolean
Me.testSuite.runBeforeEach
Me.testSuite.describe(|Test a > b|)
If (a > b) Then
Me.testSuite.addResult True, ||
runTests = True
Else
Me.testSuite.addResult False, |Expected a greater than b, a was | & CStr(a) & |, b was | & CStr(b)
runTests = False
End If
Me.testSuite.runAfterEach
End Function
End Class
Sub Initialize
'Core tests
Dim testSuite As New TestSuite(|Custom BeforeAfter Tester|)
Dim beforeAfter As New IntegerIncrementBeforeAfter
Call testSuite.addCustomBeforeAfter(beforeAfter)
'a = 1, b = 0
testSuite.describe(|Test b is false|).assertFalse(b)
'a = 2, b = 1
Call testSuite.describe(|Test a equals 2|).assertEqualsInteger(2, a)
'a = 3, b = 2
Call testSuite.describe(|Test b equals 2 primitive|).assertEqualsPrimitive(2, b)
'a = 4, b = 3
Dim f As Double
f = 3.0
'Cannot use a for these tests, because we're converting *before* incrementing
Call testSuite.describe(|Test CDbl(b) = 3.0|).assertEqualsDouble(f, CDbl(b)) 'Just passing 3.0 fails
'a = 5, b = 4
Dim c As Single
c = 4
Call testSuite.describe(|Test CSngl(b) = 4|).assertEqualsSingle(c, CSng(b))
'a = 6, b = 5
Dim d As Long
d = 5
Call testSuite.describe(|Test CLng(b) = 5|).assertEqualsLong(d, CLng(b))
'a = 7, b = 6
Dim e As Integer
e = b + 1
Call testSuite.describe(|Test a numeric = b + 1|).assertEqualsNumeric(e, a)
'a = 8, b = 8
Dim tester As New CustomTesterGreaterThan
tester.addTestSuite(testSuite).runTests
Exit Sub
End Sub