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

Skip to content

Commit c3e3f91

Browse files
committed
Added test info API to ut_runner returning ref-cursor with columns:
OWNER, PACKAGE_NAME, PROCEDURE_NAME, ANNOTATION, ANNOTATION_TEXT Resolves #571
1 parent c632dff commit c3e3f91

6 files changed

Lines changed: 73 additions & 25 deletions

File tree

docs/userguide/annotations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ The annotation cache is checked for staleness and refreshed automatically on eve
224224

225225
If you are in a situation where your database is controlled via CI/CD server and is refreshed/wiped before each run of your tests, consider building the annotation cache upfront and taking a snapshot of the database after the cache has been refreshed.
226226

227-
To build the annotation cache without actually invoking any tests, call `ut_runner.rebuild_annotation_cache(a_object_owner, a_object_type)` for every unit test owner for which you want to have the annotation cache prebuilt.
227+
To build the annotation cache without actually invoking any tests, call `ut_runner.rebuild_annotation_cache(a_object_owner)` for every unit test owner for which you want to have the annotation cache prebuilt.
228228
Example:
229229
```sql
230-
exec ut_runner.rebuild_annotation_cache('HR', 'PACKAGE');
230+
exec ut_runner.rebuild_annotation_cache('HR');
231231
```
232232

233-
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner, a_object_type)`.
233+
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner)`.
234234
Example:
235235
```sql
236236
exec ut_runner.purge_cache('HR', 'PACKAGE');

source/api/ut_runner.pkb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,31 @@ create or replace package body ut_runner is
106106
end if;
107107
end;
108108

109-
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2) is
109+
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2 := null) is
110110
begin
111-
ut_annotation_manager.rebuild_annotation_cache(a_object_owner, a_object_type);
111+
ut_annotation_manager.rebuild_annotation_cache(a_object_owner, coalesce(a_object_type,'PACKAGE'));
112112
end;
113113

114-
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2) is
114+
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2 := null) is
115115
begin
116-
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
116+
ut_annotation_manager.purge_cache(a_object_owner, coalesce(a_object_type,'PACKAGE'));
117+
end;
118+
119+
function get_unit_tests_info(a_owner varchar2, a_package_name varchar2 := null) return sys_refcursor is
120+
l_result sys_refcursor;
121+
l_filter varchar2(100);
122+
l_ut_owner varchar2(250) := ut_utils.ut_owner;
123+
begin
124+
l_filter := case when a_package_name is null then 'is null' else '= o.object_name' end;
125+
open l_result for
126+
'select o.object_owner owner, o.object_name as package_name, upper(a.subobject_name) as procedure_name,' ||
127+
' a.name annotation, a.text annotation_text' ||
128+
' from table('||l_ut_owner||'.ut_annotation_manager.get_annotated_objects(:a_owner, ''PACKAGE'')) o,' ||
129+
' table(o.annotations) a' ||
130+
' where exists (select 1 from table(o.annotations) s where s.name=''suite'') ' ||
131+
' and :a_package_name ' || l_filter
132+
using a_owner, a_package_name;
133+
return l_result;
117134
end;
118135

119136
end ut_runner;

source/api/ut_runner.pks

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,32 @@ create or replace package ut_runner authid current_user is
6262
);
6363

6464
/**
65-
* Rebuilds annotation cache for a specified schema and object type.
66-
* The procedure is called internally by `get_annotated_objects` function.
67-
* It can be used to speedup initial execution of utPLSQL on a given schema
68-
* if it is executed before any call is made to `ut.run` or `ut_runner.run` procedure.
69-
*
70-
* @param a_object_owner owner of objects to get annotations for
71-
* @param a_object_type type of objects to get annotations for
72-
*/
73-
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2);
65+
* Rebuilds annotation cache for a specified schema and object type.
66+
* It can be used to speedup execution of utPLSQL on a given schema
67+
* if it is executed before initial call made to `ut.run` or `ut_runner.run` procedure.
68+
*
69+
* @param a_object_owner owner of objects to get annotations for
70+
* @param a_object_type optional type of objects to get annotations for (defaults to 'PACKAGE')
71+
*/
72+
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2 := null);
7473

7574
/**
76-
* Removes cached information about annotations for objects of specified type and specified owner
77-
*
78-
* @param a_object_owner owner of objects to purge annotations for
79-
* @param a_object_type type of objects to purge annotations for
80-
*/
81-
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2);
75+
* Removes cached information about annotations for objects of specified type and specified owner
76+
*
77+
* @param a_object_owner owner of objects to purge annotations for
78+
* @param a_object_type optional type of objects to purge annotations for (defaults to 'PACKAGE')
79+
*/
80+
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2 := null);
81+
82+
83+
/**
84+
* Returns a ref_cursor containing information about unit tests package(s) for given owner
85+
*
86+
* @param a_owner owner of unit tests to retrieve
87+
* @param a_package_name optional name of unit test package to retrieve, if NULLm all unit test packages are returned
88+
* @return sys_refcursor columns: OWNER, PACKAGE_NAME, PROCEDURE_NAME, ANNOTATION, ANNOTATION_TEXT
89+
*/
90+
function get_unit_tests_info(a_owner varchar2, a_package_name varchar2 := null) return sys_refcursor;
8291

8392
end ut_runner;
8493
/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,22 @@ end;';
258258
ut.expect(l_actual).to_equal(0);
259259
end;
260260

261+
procedure test_get_unit_tests_info is
262+
l_expected sys_refcursor;
263+
l_actual sys_refcursor;
264+
begin
265+
--Arrange
266+
open l_expected for
267+
select 'UT3_TESTER' owner, 'DUMMY_TEST_PACKAGE' package_name,
268+
to_char(null) procedure_name, 'suite' annotation, 'dummy_test_suite' annotation_text from dual union all
269+
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', to_char(null), 'rollback', 'manual' from dual union all
270+
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 'test', 'dummy_test' from dual union all
271+
select 'UT3_TESTER', 'DUMMY_TEST_PACKAGE', 'SOME_DUMMY_TEST_PROCEDURE', 'beforetest', 'some_procedure' from dual;
272+
--Act
273+
l_actual := ut3.ut_runner.get_unit_tests_info('UT3_TESTER','DUMMY_TEST_PACKAGE');
274+
--Assert
275+
ut.expect(l_actual).to_equal(l_expected);
276+
end;
277+
261278
end;
262279
/
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
create or replace package test_ut_runner is
22

33
--%suite(ut_runner)
4-
--%suitepath(utplsql)
4+
--%suitepath(utplsql.api)
55
--%rollback(manual)
66

77
--%test(transaction stays open after the run if it was opened before the run)
@@ -43,5 +43,10 @@ create or replace package test_ut_runner is
4343
--%aftertest(cleanup_cache)
4444
procedure test_rebuild_cache_schema_type;
4545

46+
--%test(get_unit_tests_info returns a cursor containing records for a newly created test)
47+
--%beforetest(setup_cache_objects)
48+
--%aftertest(cleanup_cache)
49+
procedure test_get_unit_tests_info;
50+
4651
end;
4752
/

test/install_tests.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ whenever oserror exit failure rollback
2727
@@core/expectations/test_expect_not_to_be_null.pks
2828
@@core/expectations/test_expect_to_be_not_null.pks
2929
@@core/expectations/test_expect_to_be_null.pks
30-
@@test_ut_runner.pks
30+
@@api/test_ut_runner.pks
3131
@@core/annotations/test_annotation_manager.pks
3232
@@core/test_ut_suite.pks
3333
@@core/test_ut_test.pks
@@ -46,7 +46,7 @@ whenever oserror exit failure rollback
4646
@@core/expectations/test_expect_not_to_be_null.pkb
4747
@@core/expectations/test_expect_to_be_not_null.pkb
4848
@@core/expectations/test_expect_to_be_null.pkb
49-
@@test_ut_runner.pkb
49+
@@api/test_ut_runner.pkb
5050
@@core/annotations/test_annotation_manager.pkb
5151
@@core/test_ut_suite.pkb
5252
@@core/test_ut_test.pkb

0 commit comments

Comments
 (0)