Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d02c406

Browse files
Added the documentation for the throws exception number annotations
Resolves #585
1 parent 7cfd40e commit d02c406

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

docs/userguide/annotations.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ create or replace package test_pkg is
3737

3838
-- %test
3939
-- %displayname(Name of a test)
40+
-- %throws(-20145,-20146,-20189,-20563)
4041
procedure some_test;
4142

4243
-- %test(Name of another test)
@@ -74,6 +75,7 @@ end test_pkg;
7475
| `%suitepath(<path>)` | Package | Similar to java package. The annotation allows logical grouping of suites into hierarchies. |
7576
| `%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. |
7677
| `%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. |
7779
| `%beforeall` | Procedure | Denotes that the annotated procedure should be executed once before all elements of the suite. |
7880
| `%afterall` | Procedure | Denotes that the annotated procedure should be executed once after all elements of the suite. |
7981
| `%beforeeach` | Procedure | Denotes that the annotated procedure should be executed before each `%test` procedure in the suite. |
@@ -235,3 +237,73 @@ Example:
235237
```sql
236238
exec ut_runner.purge_cache('HR', 'PACKAGE');
237239
```
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.
306+
307+
Finished in .040591 seconds
308+
3 tests, 2 failed, 0 errored, 0 disabled, 0 warning(s)
309+
```

0 commit comments

Comments
 (0)