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
Updated documentation to assure that annotations are mentioned as `--%annotation` rather than `%annotation`
Fixed bug, where `--%throws(-00001)` would not catch exception `ORA-00001` due to leading zero.
Added full stack trace, when a different than expected exception was thrown.
Added ut_integer_list_type.
Cleanup of `ut_executable_test`
Reworked tests for `--%throws` to check for the test report text content.
@@ -4,64 +4,101 @@ Annotations are used to configure tests and suites in a declarative way similar
4
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
-
Annotations are interpreted only in the package specification and are case-insensitive. It is recommended however, to use lower-case annotations as described in this documentation.
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 places where annotations may appear:
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.)
12
+
13
+
If procedure level annotation is not placed right before procedure, it is not considered an annotation for procedure.
14
+
15
+
Example of invalid procedure level annotations
16
+
```sql
17
+
create or replace package test_pkg is
18
+
19
+
--%suite(Name of suite)
20
+
21
+
--%test
22
+
-- this single-line comment makes the TEST annotation no longer associated with the procedure
23
+
procedure first_test;
24
+
25
+
--%test
26
+
--procedure some_test; /* This TEST annotation is not associated with any procedure*/
27
+
28
+
--%test(Name of another test)
29
+
procedure another_test;
30
+
31
+
--%test
32
+
/**
33
+
* this multi-line comment makes the TEST annotation no longer associated with the procedure
34
+
*/
35
+
procedure yet_another_test;
36
+
end test_pkg;
37
+
```
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.
10
39
11
-
- at the beginning of the package specification (`%suite`, `%suitepath` etc.)
12
-
- right before a procedure (`%test`, `%beforeall`, `%beforeeach` etc.)
13
40
14
41
Package level annotations need to be separated by at least one empty line from the underlying procedure annotations.
15
42
16
-
Procedure annotations are defined right before the procedure they reference, no empty lines are allowed.
43
+
Example of invalid package level annotation.
44
+
```sql
45
+
create or replace package test_pkg is
46
+
--%suite(Name of suite)
47
+
--%test
48
+
procedure first_test;
49
+
end test_pkg;
50
+
```
17
51
18
-
If a package specification contains the `%suite` annotation, it is treated as a test package and is processed by the framework.
52
+
If a package specification contains the `--%suite` annotation, it is treated as a test package and is processed by the framework.
19
53
20
-
Some annotations accept parameters like `%suite`, `%test` and `%displayname`. The parameters for annotations need to be placed in brackets. Values for parameters should be provided without any quotation marks.
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`
21
58
22
59
# <aname="example"></a>Example of an annotated test package
23
60
24
61
```sql
25
62
create or replace package test_pkg is
26
63
27
-
--%suite(Name of suite)
28
-
--%suitepath(all.globaltests)
64
+
--%suite(Name of suite)
65
+
--%suitepath(all.globaltests)
29
66
30
-
--%beforeall
67
+
--%beforeall
31
68
procedure global_setup;
32
69
33
-
--%afterall
70
+
--%afterall
34
71
procedure global_cleanup;
35
72
36
73
/* Such comments are allowed */
37
74
38
-
--%test
39
-
--%displayname(Name of a test)
40
-
--%throws(-20145,-20146,-20189,-20563)
75
+
--%test
76
+
--%displayname(Name of a test)
77
+
--%throws(-20145,-20146,-20189,-20563)
41
78
procedure some_test;
42
79
43
-
--%test(Name of another test)
44
-
--%beforetest(setup_another_test)
45
-
--%aftertest(cleanup_another_test)
80
+
--%test(Name of another test)
81
+
--%beforetest(setup_another_test)
82
+
--%aftertest(cleanup_another_test)
46
83
procedure another_test;
47
84
48
-
--%test
49
-
--%displayname(Name of test)
50
-
--%disabled
85
+
--%test
86
+
--%displayname(Name of test)
87
+
--%disabled
51
88
procedure disabled_test;
52
89
53
-
--%test(Name of test)
54
-
--%rollback(manual)
90
+
--%test(Name of test)
91
+
--%rollback(manual)
55
92
procedure no_transaction_control_test;
56
93
57
94
procedure setup_another_test;
58
95
59
96
procedure cleanup_another_test;
60
97
61
-
--%beforeeach
98
+
--%beforeeach
62
99
procedure test_setup;
63
100
64
-
--%aftereach
101
+
--%aftereach
65
102
procedure test_cleanup;
66
103
67
104
end test_pkg;
@@ -75,7 +112,7 @@ end test_pkg;
75
112
|`%suitepath(<path>)`| Package | Similar to java package. The annotation allows logical grouping of suites into hierarchies. |
76
113
|`%displayname(<description>)`| Package/procedure | Human-readable and meaningful description of a suite/test. `%displayname(Name of the suite/test)`. The annotation is provided for flexibility and convenience only. It has exactly the same meaning as `<description>` in `test` and `suite` annotations. If description is provided using both `suite`/`test` and `displayname`, then the one defined as last takes precedence. |
77
114
|`%test(<description>)`| Procedure | Denotes that the annotated procedure is a unit test procedure. Optional test description can by provided (see `displayname`). |
78
-
|`%throws(<exception_number>)`|Test Procedure | Denotes that the annotated test procedure must throws one of the exception numbers written. If there are no valid number the annotation is ignored. Only applies to test procedures. |
115
+
|`%throws(<exception_number>[,<exception_number>[,...]])`| Procedure | Denotes that the annotated procedure must throw one of the exception numbers provided. If no valid numbers were provided as annotation parameters the annotation is ignored. Applicable to test procedures only. |
79
116
|`%beforeall`| Procedure | Denotes that the annotated procedure should be executed once before all elements of the suite. |
80
117
|`%afterall`| Procedure | Denotes that the annotated procedure should be executed once after all elements of the suite. |
81
118
|`%beforeeach`| Procedure | Denotes that the annotated procedure should be executed before each `%test` procedure in the suite. |
@@ -105,17 +142,17 @@ The `%suitepath` annotation is used for such grouping. Even though test packages
105
142
```sql
106
143
create or replace package test_payment_recognition as
107
144
108
-
--%suite(Payment recognition tests)
109
-
--%suitepath(payments)
145
+
--%suite(Payment recognition tests)
146
+
--%suitepath(payments)
110
147
111
-
--%test(Recognize payment by policy number)
148
+
--%test(Recognize payment by policy number)
112
149
procedure test_recognize_by_num;
113
150
114
-
--%test
115
-
--%displayname(Recognize payment by payment purpose)
151
+
--%test
152
+
--%displayname(Recognize payment by payment purpose)
116
153
procedure test_recognize_by_purpose;
117
154
118
-
--%test(Recognize payment by customer)
155
+
--%test(Recognize payment by customer)
119
156
procedure test_recognize_by_customer;
120
157
121
158
end test_payment_recognition;
@@ -125,14 +162,14 @@ And payments set off test package:
125
162
```sql
126
163
create or replace package test_payment_set_off as
127
164
128
-
--%suite(Payment set off tests)
129
-
--%suitepath(payments)
165
+
--%suite(Payment set off tests)
166
+
--%suitepath(payments)
130
167
131
-
--%test(Set off creation test)
168
+
--%test(Set off creation test)
132
169
procedure test_create_set_off;
133
170
134
-
--%test
135
-
--%displayname(Set off annulation test)
171
+
--%test
172
+
--%displayname(Set off annulation test)
136
173
procedure test_annulate_set_off;
137
174
138
175
end test_payment_set_off;
@@ -145,12 +182,12 @@ An additional advantage of such grouping is the fact that every element level of
145
182
```sql
146
183
create or replace package payments as
147
184
148
-
--%suite(Payments)
185
+
--%suite(Payments)
149
186
150
-
--%beforeall
187
+
--%beforeall
151
188
procedure set_common_payments_data;
152
189
153
-
--%afterall
190
+
--%afterall
154
191
procedure reset_common_paymnets_data;
155
192
156
193
end payments;
@@ -169,7 +206,7 @@ In general, your unit tests should not use transaction control as long as the co
169
206
Keeping the transactions uncommitted allows your changes to be isolated and the execution of tests does not impact others who might be using a shared development database.
170
207
171
208
If you are in a situation where the code you are testing uses transaction control (common case with ETL code), then your tests probably should not use the default automatic transaction control.
172
-
In that case use the annotation `--%rollback(manual)` on the suite level to disable automatic transaction control for the entire suite.
209
+
In that case use the annotation `--%rollback(manual)` on the suite level to disable automatic transaction control for the entire suite.
173
210
If you are using nested suites, you need to make sure that the entire suite all the way to the root is using manual transaction control.
174
211
175
212
It is possible with utPLSQL to change the transaction control on individual suites or tests that are part of complex suite.
utPLSQL uses the `%throws` annotation to allow the user to delimit which exception numbers a test must throws.
244
-
245
-
If `%throws` is specified for one test and nothing is raise or a different exception than the annotated one is thrown, the test is marked as failed.
280
+
The `--%throws` annotation allows you to specify a list of exception numbers that can be expected from a test.
246
281
247
-
The framework discards the bad arguments, `--%throws(7894562, operaqk, -=1, -20496, pow74d, posdfk3)` it converts that to this `--%throws(-20496)`.
248
-
If the arguments is empty `--%throws()`,`--%throws`, or only no valid arguments are provided `--%throws(abe, 723pf)` the annotation is ignored.
282
+
If `--%throws(-20001,-20002)` is specified and no exception is raised or the exception raised is not on the list of provided exception numbers, the test is marked as failed.
249
283
250
-
Example how to use the annotation:
284
+
The framework ignores bad arguments. `--%throws(7894562, operaqk, -=1, -20496, pow74d, posdfk3)` will be interpreted as `--%throws(-20496)`.
285
+
The annotation is ignored, when no valid arguments are provided `--%throws()`,`--%throws`, `--%throws(abe, 723pf)`.
251
286
252
-
```
287
+
Example:
288
+
```sql
253
289
create or replace package example_pgk as
254
290
255
-
--%suite(Example Throws Annotation)
291
+
--%suite(Example Throws Annotation)
256
292
257
-
-%test(Throws one of the listed exceptions)
293
+
--%test(Throws one of the listed exceptions)
258
294
--%throws(-20145,-20146, -20189 ,-20563)
259
295
procedure raised_one_listed_exception;
260
296
261
-
--%test(Throws diff exception)
297
+
--%test(Throws different exception than expected)
262
298
--%throws(-20144)
263
-
procedure raised_diff_exception;
299
+
procedure raised_different_exception;
300
+
301
+
--%test(Throws different exception than listed)
302
+
--%throws(-20144,-00001,-20145)
303
+
procedure raised_unlisted_exception;
264
304
265
-
--%test(Givess failure when a exception is expected and nothing is thrown)
305
+
--%test(Gives failure when an exception is expected and nothing is thrown)
266
306
--%throws(-20459, -20136, -20145)
267
307
procedure nothing_thrown;
268
308
269
309
end;
270
-
```
271
-
272
-
```
273
-
create package body annotated_package_with_throws is
310
+
/
311
+
create or replace package body example_pgk is
274
312
procedure raised_one_listed_exception is
275
313
begin
276
314
raise_application_error(-20189, 'Test error');
277
315
end;
278
316
279
-
procedure raised_diff_exception is
317
+
procedure raised_different_exception is
318
+
begin
319
+
raise_application_error(-20143, 'Test error');
320
+
end;
321
+
322
+
procedure raised_unlisted_exception is
280
323
begin
281
324
raise_application_error(-20143, 'Test error');
282
325
end;
283
326
284
327
procedure nothing_thrown is
285
328
begin
286
-
null;
329
+
ut.expect(1).to_equal(1);
287
330
end;
288
331
end;
332
+
/
333
+
334
+
exec ut.run('example_pgk');
289
335
```
290
336
291
-
The test results are:
292
-
337
+
Running the test will give report:
293
338
```
294
339
Example Throws Annotation
295
-
Throws one of the listed exceptions [.011 sec]
296
-
Throws diff exception [.011 sec] (FAILED - 1)
297
-
Givess failure when a exception is expected and nothing is thrown [.014 sec] (FAILED - 2)
298
-
340
+
Throws one of the listed exceptions [.018 sec]
341
+
Throws different exception than expected [.008 sec] (FAILED - 1)
342
+
Throws different exception than listed [.007 sec] (FAILED - 2)
343
+
Gives failure when an exception is expected and nothing is thrown [.002 sec] (FAILED - 3)
344
+
299
345
Failures:
300
-
301
-
1) raised_diff_exception
302
-
UT3.annotated_package_with_throws.raised_diff_exception Actual: -20143 was expected to be one of (-20144)
303
-
304
-
2) nothing_thrown
305
-
UT3.annotated_package_with_throws.nothing_thrown Expected one of exceptions (-20459,-20136,-20145) but nothing was raised.
Copy file name to clipboardExpand all lines: docs/userguide/exception-reporting.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,19 @@
2
2
3
3
The utPLSQL is responsible for handling exceptions wherever they occur in the test run. utPLSQL is trapping most of the exceptions so that the test execution is not affected by individual tests or test packages throwing an exception.
4
4
The framework provides a full stacktrace for every exception that was thrown. The stacktrace is clean and does not include any utPLSQL library calls in it.
5
-
To achieve rerunability, the ORA-04068, ORA-04061 exceptions are not handled and test execution will be interrupted if such exception is encountered. This is because of how Oracle behaves on those exceptions.
5
+
To achieve rerunability, the package state invalidation exceptions (ORA-04068, ORA-04061) are not handled and test execution will be interrupted if such exceptions are encountered. This is because of how Oracle behaves on those exceptions.
6
6
7
7
Test execution can fail for different reasons. The failures on different exceptions are handled as follows:
8
-
* A test package without body - each `%test` is reported as failed with exception, nothing is executed
9
-
* A test package with _invalid body_ - each `%test` is reported as failed with exception, nothing is executed
8
+
* A test package without body - each `--%test` is reported as failed with exception, nothing is executed
9
+
* A test package with _invalid body_ - each `--%test` is reported as failed with exception, nothing is executed
10
10
* A test package with _invalid spec_ - package is not considered a valid unit test package and is excluded from execution. When trying to run a test package with invalid spec explicitly, exception is raised. Only valid specifications are parsed for annotations
11
-
* A test package that is raising an exception in `%beforeall` - each `%test` is reported as failed with exception, `%test`, `%beforeeach`, `%beforetest`, `%aftertest` and `%aftereach` are not executed. `%afterall` is executed to allow cleanup of whatever was done in `%beforeall`
12
-
* A test package that is raising an exception in `%beforeeach` - each `%test` is reported as failed with exception, `%test`, `%beforetest` and `%aftertest` is not executed. The `%aftereach` and `%afterall` blocks are getting executed to allow cleanup of whatever was done in `%before...` blocks
13
-
* A test package that is raising an exception in `%beforetest` - the `%test` is reported as failed with exception, `%test` is not executed. The `%aftertest`, `%aftereach` and `%afterall` blocks are getting executed to allow cleanup of whatever was done in `%before...` blocks
14
-
* A test package that is raising an exception in `%test` - the `%test` is reported as failed with exception. The execution of other blocks continues normally
15
-
* A test package that is raising an exception in `%aftertest` - the `%test` is reported as failed with exception. The execution of other blocks continues normally
16
-
* A test package that is raising an exception in `%aftereach` - each `%test` is reported as failed with exception.
17
-
* A test package that is raising an exception in `%afterall` - all blocks of the package are executed, as the `%afterall` is the last step of package execution. Exception in `%afterall` is not affecting test results. A warning with exception stacktrace is displayed in the summary
11
+
* A test package that is raising an exception in `--%beforeall` - each `--%test` is reported as failed with exception, `--%test`, `--%beforeeach`, `--%beforetest`, `--%aftertest` and `--%aftereach` are not executed. `--%afterall` is executed to allow cleanup of whatever was done in `--%beforeall`
12
+
* A test package that is raising an exception in `--%beforeeach` - each `--%test` is reported as failed with exception, `--%test`, `--%beforetest` and `--%aftertest` is not executed. The `--%aftereach` and `--%afterall` blocks are getting executed to allow cleanup of whatever was done in `--%before...` blocks
13
+
* A test package that is raising an exception in `--%beforetest` - the `--%test` is reported as failed with exception, `--%test` is not executed. The `--%aftertest`, `--%aftereach` and `--%afterall` blocks are getting executed to allow cleanup of whatever was done in `--%before...` blocks
14
+
* A test package that is raising an exception in `--%test` - the `--%test` is reported as failed with exception. The execution of other blocks continues normally
15
+
* A test package that is raising an exception in `--%aftertest` - the `--%test` is reported as failed with exception. The execution of other blocks continues normally
16
+
* A test package that is raising an exception in `--%aftereach` - each `--%test` is reported as failed with exception.
17
+
* A test package that is raising an exception in `--%afterall` - all blocks of the package are executed, as the `--%afterall` is the last step of package execution. Exception in `--%afterall` is not affecting test results. A warning with exception stacktrace is displayed in the summary
18
18
19
19
20
20
Example of reporting with exception thrown in `%beforetest`:
0 commit comments