You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Annotations are used to configure tests and suites in a declarative way similar to modern OOP languages. This way, test configuration is stored along with the test logic inside the test package.
4
-
No configuration files or tables are needed. The annotation names are based on popular testing frameworks such as jUnit.
4
+
No configuration files or tables are needed. The annotation names are based on popular testing frameworks such as JUnit.
5
5
The framework runner searches for all the suitable annotated packages, automatically configures suites, forms the suite hierarchy, executes it and reports results in specified formats.
6
6
7
7
Annotations are interpreted only in the package specification and are case-insensitive. We strongly recommend using lower-case annotations as described in this documentation.
8
8
9
-
There are two locations where annotations can be placed:
10
-
- Package level annotations can be placed at the very top of the package specification (`--%suite`, `--%suitepath` etc.)
11
-
- Procedure level annotations can be placed right before a procedure (`--%test`, `--%beforeall`, `--%beforeeach` etc.)
9
+
There are two distinct types of annotations, identified by their location in package:
10
+
- Procedure level annotations - placed directly before a procedure (`--%test`, `--%beforeall`, `--%beforeeach` etc.).
11
+
- Package level annotations - placed at any place in package except directly before procedure (`--%suite`, `--%suitepath` etc.).
12
+
13
+
We strongly recommend putting package level annotations at the very top of package except for the `--%context` annotations (described below)
14
+
12
15
13
16
If procedure level annotation is not placed right before procedure, it is not considered an annotation for procedure.
14
17
@@ -35,10 +38,10 @@ create or replace package test_pkg is
35
38
procedure yet_another_test;
36
39
end test_pkg;
37
40
```
38
-
Procedure annotations are defined right before the procedure they reference, no empty lines are allowed, no comment lines can exist between annotation and the procedure.
41
+
Procedure level annotations must be defined right before the procedure they reference, no empty lines are allowed, no comment lines can exist between annotation and the procedure.
39
42
40
43
41
-
Package level annotations need to be separated by at least one empty line from the underlying procedure annotations.
44
+
Package level annotations need to be separated by at least one empty line from a procedure procedure or procedure annotation.
42
45
43
46
Example of invalid package level annotation.
44
47
```sql
@@ -48,42 +51,57 @@ create or replace package test_pkg is
48
51
procedure first_test;
49
52
end test_pkg;
50
53
```
54
+
In the above example, the `--%suite` annotation is ignored, as it is in fact associated with `procedure first_test`. Association with procedure takes precedence over association with package.
51
55
52
-
If a package specification contains the `--%suite` annotation, it is treated as a test package and is processed by the framework.
53
-
54
-
Some annotations accept parameters like `--%suite`, `--%test` and `--%displayname`. The parameters for annotations need to be placed in brackets.
55
-
Values for parameters should be provided without any quotation marks.
56
-
If the parameters are placed without brackets or with incomplete brackets, they will be ignored.
57
-
Example: `--%suite(The name of suite without closing bracket`
58
-
59
-
# <aname="example"></a>Example of an annotated test package
56
+
## Order of execution
60
57
61
58
```sql
62
-
create or replace package test_pkg is
59
+
create or replace package test_employee_pkg is
63
60
64
-
--%suite(Name of suite)
65
-
--%suitepath(all.globaltests)
61
+
--%suite(Employee management)
62
+
--%suitepath(com.my_company.hr)
63
+
--%rollback(auto)
64
+
65
+
--%beforeall
66
+
procedure setup_employees;
66
67
67
68
--%beforeall
68
-
procedure global_setup;
69
+
procedure setup_departments;
69
70
70
71
--%afterall
71
-
procedure global_cleanup;
72
+
procedure cleanup_log_table;
72
73
73
-
/* Such comments are allowed */
74
+
--%context(add_employee)
74
75
75
-
--%test
76
-
--%displayname(Name of a test)
77
-
--%throws(-20145,-20146,-20189,-20563)
78
-
procedure some_test;
76
+
--%beforeeach
77
+
procedure setup_for_add_employees;
79
78
80
-
--%test(Name of another test)
79
+
--%test(Raises exception when employee already exists)
80
+
--%throws(-20145)
81
+
procedure add_existing_employee;
82
+
83
+
--%test(Inserts employee to emp table)
84
+
procedure add_employee;
85
+
86
+
--%endcontext
87
+
88
+
89
+
--%context(remove_employee)
90
+
91
+
--%beforeall
92
+
procedure setup_for_remove_employee;
93
+
94
+
--%test(Removed employee from emp table)
95
+
procedure del_employee;
96
+
97
+
--%endcontext
98
+
99
+
--%test(Test without context)
81
100
--%beforetest(setup_another_test)
82
101
--%aftertest(cleanup_another_test)
83
-
procedure another_test;
102
+
procedure some_test;
84
103
85
-
--%test
86
-
--%displayname(Name of test)
104
+
--%test(Name of test)
87
105
--%disabled
88
106
procedure disabled_test;
89
107
@@ -96,15 +114,76 @@ create or replace package test_pkg is
96
114
procedure cleanup_another_test;
97
115
98
116
--%beforeeach
99
-
procedure test_setup;
117
+
procedure set_session_context;
100
118
101
119
--%aftereach
102
-
procedure test_cleanup;
120
+
procedure cleanup_session_context;
103
121
104
-
end test_pkg;
122
+
end test_employee_pkg;
105
123
```
106
124
107
-
# Supported annotations
125
+
When processing the test suite `test_employee_pkg` defined in [Example of annotated test package](#example), the order of execution will be as follows.
126
+
127
+
```
128
+
create a savepoint 'before-suite'
129
+
execute setup_employees (--%beforeall)
130
+
execute setup_departments (--%beforeall)
131
+
132
+
create a savepoint 'before-context'
133
+
create savepoint 'before-test'
134
+
execute test_setup (--%beforeeach)
135
+
execute setup_for_add_employees (--%beforeeach from context)
136
+
execute add_existing_employee (--%test)
137
+
execute test_cleanup (--%aftereach)
138
+
rollback to savepoint 'before-test'
139
+
create savepoint 'before-test' (--%suite)
140
+
execute test_setup (--%beforeeach)
141
+
execute setup_for_add_employees (--%beforeeach from context)
142
+
execute add_employee (--%test)
143
+
execute test_cleanup (--%aftereach)
144
+
rollback to savepoint 'before-test'
145
+
rollback to savepoint 'before-context'
146
+
147
+
create a savepoint 'before-context'
148
+
execute setup_for_remove_employee (--%beforeall from context)
149
+
create savepoint 'before-test'
150
+
execute test_setup (--%beforeeach)
151
+
execute add_existing_employee (--%test)
152
+
execute test_cleanup (--%aftereach)
153
+
rollback to savepoint 'before-test'
154
+
rollback to savepoint 'before-context'
155
+
156
+
create savepoint 'before-test'
157
+
execute test_setup (--%beforeeach)
158
+
execute some_test (--%test)
159
+
execute test_cleanup (--%aftereach)
160
+
rollback to savepoint 'before-test'
161
+
162
+
create savepoint 'before-test'
163
+
execute test_setup (--%beforeeach)
164
+
execute setup_another_test (--%beforetest)
165
+
execute another_test (--%test)
166
+
execute cleanup_another_test (--%aftertest)
167
+
execute test_cleanup (--%beforeeach)
168
+
rollback to savepoint 'before-test'
169
+
170
+
mark disabled_test as disabled (--%test --%disabled)
171
+
172
+
execute test_setup (--%beforeeach)
173
+
execute no_transaction_control_test (--%test)
174
+
execute test_cleanup (--%aftertest)
175
+
176
+
execute global_cleanup (--%afterall)
177
+
rollback to savepoint 'before-suite'
178
+
```
179
+
180
+
**Note**
181
+
>utPLSQL does not guarantee ordering of tests in suite. On contrary utPLSQL might give random order of tests/contexts in suite.
182
+
>
183
+
>Order of execution within multiple occurrences of `before`/`after` procedures is determined by the order of annotations in specific block (context/suite) of package specification.
184
+
185
+
186
+
## Supported annotations
108
187
109
188
| Annotation |Level| Description |
110
189
| --- | --- | --- |
@@ -121,10 +200,25 @@ end test_pkg;
121
200
|`--%aftertest(<procedure_name>)`| Procedure | Denotes that mentioned procedure should be executed after the annotated `%test` procedure. |
122
201
|`--%rollback(<type>)`| Package/procedure | Defines transaction control. Supported values: `auto`(default) - a savepoint is created before invocation of each "before block" is and a rollback to specific savepoint is issued after each "after" block; `manual` - rollback is never issued automatically. Property can be overridden for child element (test in suite) |
123
202
|`--%disabled`| Package/procedure | Used to disable a suite or a test. Disabled suites/tests do not get executed, they are however marked and reported as disabled in a test run. |
203
+
|`--%context(<description>)`| Package | Denotes start of a nested context (sub-suite) in a suite package |
204
+
|`--%endcontext`| Package | Denotes end of a nested context (sub-suite) in a suite package |
205
+
206
+
207
+
**Note**
208
+
>Package is considered a test-suite only when package specification contains the `--%suite` annotation at the package level.
209
+
>
210
+
>Some annotations like `--%suite`, `--%test` and `--%displayname` accept parameters. The parameters for annotations need to be placed in brackets.
211
+
Values for parameters should be provided without any quotation marks.
212
+
If the parameters are placed without brackets or with incomplete brackets, they will be ignored.
213
+
>
214
+
>Example: `--%suite(The name of suite without closing bracket`
124
215
125
216
# Suitepath concept
126
217
127
-
It is very likely that the application for which you are going to introduce tests consists of many different packages or procedures/functions. Usually procedures can be logically grouped inside a package, there also might be several logical groups of procedure in a single package or even packages themselves might relate to a common module.
218
+
It is very likely that the application for which you are going to introduce tests consists of many different packages, procedures and functions.
219
+
Usually procedures can be logically grouped inside a package, there also might be several logical groups of procedures in a single package and packages might be grouped into modules and modules into subject areas.
220
+
221
+
As your project grows, the codebase will grow to. utPLSQL allows you to group packages into modules and modules into
128
222
129
223
Let's say you have a complex insurance application that deals with policies, claims and payments. The payment module contains several packages for payment recognition, charging, planning etc. The payment recognition module among others contains a complex `recognize_payment` procedure that associates received money to the policies.
130
224
@@ -135,7 +229,6 @@ If you want to create tests for your application it is recommended to structure
135
229
* Payment tests
136
230
* Payments recognition
137
231
* Payments set off
138
-
* Payouts
139
232
140
233
The `%suitepath` annotation is used for such grouping. Even though test packages are defined in a flat structure the `%suitepath` is used by the framework to form them into a hierarchical structure. Your payments recognition test package might look like:
141
234
@@ -148,8 +241,7 @@ create or replace package test_payment_recognition as
148
241
--%test(Recognize payment by policy number)
149
242
procedure test_recognize_by_num;
150
243
151
-
--%test
152
-
--%displayname(Recognize payment by payment purpose)
244
+
--%test(Recognize payment by payment purpose)
153
245
procedure test_recognize_by_purpose;
154
246
155
247
--%test(Recognize payment by customer)
@@ -165,12 +257,11 @@ create or replace package test_payment_set_off as
165
257
--%suite(Payment set off tests)
166
258
--%suitepath(payments)
167
259
168
-
--%test(Set off creation test)
260
+
--%test(Creates set off)
169
261
procedure test_create_set_off;
170
262
171
-
--%test
172
-
--%displayname(Set off annulation test)
173
-
procedure test_annulate_set_off;
263
+
--%test(Cancels set off)
264
+
procedure test_cancel_set_off;
174
265
175
266
end test_payment_set_off;
176
267
```
@@ -221,38 +312,12 @@ Doing so allows your tests to use the framework's automatic transaction control
221
312
When you are testing code that performs explicit or implicit commits, you may set the test procedure to run as an autonomous transaction with `pragma autonomous_transaction`.
222
313
Keep in mind that when your test runs as autonomous transaction it will not see the data prepared in a setup procedure unless the setup procedure committed the changes.
223
314
224
-
# Order of execution
225
-
226
-
When processing the test suite `test_pkg` defined in [Example of annotated test package](#example), the order of execution will be as follows.
227
-
228
-
```
229
-
create a savepoint 'beforeall'
230
-
execute global_setup
231
-
232
-
create savepoint 'beforeeach'
233
-
execute test_setup
234
-
execute some_test
235
-
execute test_cleanup
236
-
rollback to savepoint 'beforeeach'
237
-
238
-
create savepoint 'beforeeach'
239
-
execute test_setup
240
-
execute setup_another_test
241
-
execute another_test
242
-
execute cleanup_another_test
243
-
execute test_cleanup
244
-
rollback to savepoint 'beforeeach'
245
-
246
-
mark disabled_test as disabled
247
-
248
-
execute test_setup
249
-
execute no_transaction_control_test
250
-
execute test_cleanup
251
-
252
-
execute global_cleanup
253
-
rollback to savepoint 'beforeall'
254
-
255
-
```
315
+
**Note**
316
+
> The `--%suitepath` annotation, when used, must be provided with a value of path.
317
+
> The path in suitepath cannot contain spaces. Dot (.) identifies individual elements of the path.
0 commit comments