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
Copy file name to clipboardExpand all lines: docs/userguide/annotations.md
+72Lines changed: 72 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,7 @@ create or replace package test_pkg is
37
37
38
38
-- %test
39
39
-- %displayname(Name of a test)
40
+
-- %throws(-20145,-20146,-20189,-20563)
40
41
procedure some_test;
41
42
42
43
-- %test(Name of another test)
@@ -74,6 +75,7 @@ end test_pkg;
74
75
|`%suitepath(<path>)`| Package | Similar to java package. The annotation allows logical grouping of suites into hierarchies. |
75
76
|`%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. |
76
77
|`%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. |
77
79
|`%beforeall`| Procedure | Denotes that the annotated procedure should be executed once before all elements of the suite. |
78
80
|`%afterall`| Procedure | Denotes that the annotated procedure should be executed once after all elements of the suite. |
79
81
|`%beforeeach`| Procedure | Denotes that the annotated procedure should be executed before each `%test` procedure in the suite. |
@@ -235,3 +237,73 @@ Example:
235
237
```sql
236
238
exec ut_runner.purge_cache('HR', 'PACKAGE');
237
239
```
240
+
241
+
# Throws annotation
242
+
243
+
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.
246
+
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.
249
+
250
+
Example how to use the annotation:
251
+
252
+
```
253
+
create or replace package example_pgk as
254
+
255
+
-- %suite(Example Throws Annotation)
256
+
257
+
-%test(Throws one of the listed exceptions)
258
+
--%throws(-20145,-20146, -20189 ,-20563)
259
+
procedure raised_one_listed_exception;
260
+
261
+
--%test(Throws diff exception)
262
+
--%throws(-20144)
263
+
procedure raised_diff_exception;
264
+
265
+
--%test(Givess failure when a exception is expected and nothing is thrown)
266
+
--%throws(-20459, -20136, -20145)
267
+
procedure nothing_thrown;
268
+
269
+
end;
270
+
```
271
+
272
+
```
273
+
create package body annotated_package_with_throws is
274
+
procedure raised_one_listed_exception is
275
+
begin
276
+
raise_application_error(-20189, 'Test error');
277
+
end;
278
+
279
+
procedure raised_diff_exception is
280
+
begin
281
+
raise_application_error(-20143, 'Test error');
282
+
end;
283
+
284
+
procedure nothing_thrown is
285
+
begin
286
+
null;
287
+
end;
288
+
end;
289
+
```
290
+
291
+
The test results are:
292
+
293
+
```
294
+
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
+
299
+
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.
0 commit comments