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

Skip to content

Commit fc9b46f

Browse files
authored
Merge pull request #699 from utPLSQL/feature/beforetest_doc_update
Updated documentation for beforetest/aftertest
2 parents 74f11e2 + a5fe6f9 commit fc9b46f

1 file changed

Lines changed: 50 additions & 14 deletions

File tree

docs/userguide/annotations.md

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ We strongly recommend putting package level annotations at the very top of packa
2626
| `--%afterall` | Procedure | Denotes that the annotated procedure should be executed once after all elements of the suite. |
2727
| `--%beforeeach` | Procedure | Denotes that the annotated procedure should be executed before each `%test` procedure in the suite. |
2828
| `--%aftereach` | Procedure | Denotes that the annotated procedure should be executed after each `%test` procedure in the suite. |
29-
| `--%beforetest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed before the annotated `%test` procedure. |
30-
| `--%aftertest(<procedure_name>)` | Procedure | Denotes that mentioned procedure should be executed after the annotated `%test` procedure. |
29+
| `--%beforetest(<[owner.[package.]]procedure_name>[,...])` | Procedure | Denotes that mentioned procedure(s) should be executed before the annotated `%test` procedure. |
30+
| `--%aftertest(<[owner.[package.]]procedure_name>[,...]>)` | Procedure | Denotes that mentioned procedure(s) should be executed after the annotated `%test` procedure. |
3131
| `--%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) |
3232
| `--%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. |
3333
| `--%context(<name>)` | Package | Denotes start of a named context (sub-suite) in a suite package |
@@ -685,12 +685,15 @@ Finished in .018115 seconds
685685

686686
### Beforetest
687687

688-
Indicates a specific setup to be executed for a test.
689-
Used alongside `--%test` annotation. Indicates procedure name to be executed before specific test.
688+
Indicates specific setup procedure(s) to be executed for a test. The procedure(s) can be located either:
689+
- within current package (package name is optional)
690+
- within another package
691+
692+
The annotation need to be placed alongside `--%test` annotation.
690693

691694
The `--%beforetest` procedures are executed after invoking all `--%beforeeach` for a test.
692695

693-
If a test is marked as disabled the `--%beforetest` procedure is not invoked for that test.
696+
If a test is marked as disabled the `--%beforetest` procedures are not invoked for that test.
694697

695698
If `--%beforetest` raises an unhandled exception the following will happen:
696699
- the following `--%beforetest` for that test **will not be executed**
@@ -701,16 +704,31 @@ If `--%beforetest` raises an unhandled exception the following will happen:
701704

702705
When multiple `--%beforetest` procedures are defined for a test, all of them will be executed before invoking the test.
703706

704-
For multiple `--%beforetest` procedures order of execution is defined by annotation position in the package specification.
707+
The order of execution for `--%beforetest` procedures is defined by:
708+
- position of procedure on the list within single annotation
709+
- annotation position
705710

706711
As a rule, the `--%beforetest` execution gets aborted if preceding `--%beforeeach` or `--%beforetest` failed.
707712

708713
```sql
714+
create or replace package shared_package as
715+
procedure do_some_stuff;
716+
end;
717+
/
718+
719+
create or replace package body shared_package as
720+
procedure do_some_stuff is
721+
begin
722+
dbms_output.put_line('---DO_SOME_STUFF invoked ---');
723+
end;
724+
end;
725+
/
726+
709727
create or replace package test_package as
710728
--%suite(Tests for a package)
711729

712730
--%test(Description of tested behavior)
713-
--%beforetest(setup_for_a_test)
731+
--%beforetest(setup_for_a_test, shared_package.do_some_stuff)
714732
--%beforetest(another_setup_for_a_test)
715733
procedure some_test;
716734

@@ -754,6 +772,7 @@ exec ut.run('test_package');
754772
Tests for a package
755773
Description of tested behavior [.011 sec]
756774
---SETUP_FOR_A_TEST invoked ---
775+
---DO_SOME_STUFF invoked ---
757776
---ANOTHER_SETUP_FOR_A_TEST invoked ---
758777
---SOME_TEST invoked ---
759778
Description of another behavior [.005 sec]
@@ -767,12 +786,13 @@ Finished in .018446 seconds
767786

768787
### Aftertest
769788

770-
Indicates a specific cleanup to be executed for a test.
771-
Used alongside `--%test` annotation. Indicates procedure name to be executed after specific test.
772-
773-
The `--%aftertest` procedures are executed before invoking any `--%aftereach` for a test.
789+
Indicates specific cleanup procedure(s) to be executed for a test. The procedure(s) can be located either:
790+
- within current package (package name is optional)
791+
- within another package
792+
793+
The annotation need to be placed alongside `--%test` annotation.
774794

775-
If a test is marked as disabled the `--%aftertest` procedure is not invoked for that test.
795+
If a test is marked as disabled the `--%aftertest` procedures are not invoked for that test.
776796

777797
If `--%aftertest` raises an unhandled exception the following will happen:
778798
- the test will be marked as errored and exception stack trace will be captured and reported
@@ -782,16 +802,31 @@ If `--%aftertest` raises an unhandled exception the following will happen:
782802

783803
When multiple `--%aftertest` procedures are defined for a test, all of them will be executed before invoking the test.
784804

785-
For multiple `--%aftertest` procedures order of execution is defined by annotation position in the package specification.
805+
The order of execution for `--%aftertest` procedures is defined by:
806+
- position of procedure on the list within single annotation
807+
- annotation position
786808

787809
As a rule, the `--%aftertest` gets executed even if the associated `--%beforeeach`, `--%beforetest`, `--%test` or other `--%aftertest` procedures have raised unhandled exceptions.
788810

789811
```sql
812+
create or replace package shared_package as
813+
procedure do_some_stuff;
814+
end;
815+
/
816+
817+
create or replace package body shared_package as
818+
procedure do_some_stuff is
819+
begin
820+
dbms_output.put_line('---DO_SOME_STUFF invoked ---');
821+
end;
822+
end;
823+
/
824+
790825
create or replace package test_package as
791826
--%suite(Tests for a package)
792827

793828
--%test(Description of tested behavior)
794-
--%aftertest(cleanup_for_a_test)
829+
--%aftertest(cleanup_for_a_test, shared_package.do_some_stuff)
795830
--%aftertest(another_cleanup_for_a_test)
796831
procedure some_test;
797832

@@ -836,6 +871,7 @@ Tests for a package
836871
Description of tested behavior [.01 sec]
837872
---SOME_TEST invoked ---
838873
---CLEANUP_FOR_A_TEST invoked ---
874+
---DO_SOME_STUFF invoked ---
839875
---ANOTHER_CLEANUP_FOR_A_TEST invoked ---
840876
Description of another behavior [.006 sec]
841877
---OTHER_TEST invoked ---

0 commit comments

Comments
 (0)