Skip to content

Commit eeae79b

Browse files
committed
Added documentation for new functionality.
Added default value for owner, when calling `get_suites_info`
1 parent f342195 commit eeae79b

7 files changed

Lines changed: 93 additions & 8 deletions

File tree

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The framework follows industry standards and best patterns of modern Unit Testin
1010
- [Expectations](userguide/expectations.md)
1111
- [Advanced data comparison](userguide/advanced_data_comparison.md)
1212
- [Running unit tests](userguide/running-unit-tests.md)
13+
- [Querying for test suites](userguide/querying_suites.md)
1314
- [Testing best pracitces](userguide/best-practices.md)
1415
- [Upgrade utPLSQL](userguide/upgrade.md)
1516
- Reporting

docs/userguide/querying_suites.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Qyerying for test suites
2+
3+
4+
## Obtaining information about suites
5+
6+
utPLSQL framework provides ability to read inforamtion about unit test suites that exist in a schema.
7+
8+
Pipelined table function `ut_runner.get_suites_info(a_owner, a_package_name)` allows you to retrieve information about:
9+
10+
- all suites that exist in a given user/schema
11+
- individual test suite pacakage
12+
13+
Querying the data from function provides the follwing details:
14+
15+
- `object_owner` - the owner of test suite packages
16+
- `object_name` - the name of test suite package
17+
- `item_name` - the name of suite/test
18+
- `item_description` - the description of suite/suite item
19+
- `item_type` - the type of item (UT_SUITE/UT_SUITE_CONTEXT/UT_TEST/UT_LOGICAL_SUITE)
20+
- `item_line_no` - line_number where annotation identifying the item exists
21+
- `path` - suitepath of the item
22+
- `disabled_flag` - (0/1) indicator if item is disabled by --%disabled annotation
23+
24+
To get list of all test suites in current schema
25+
```sql
26+
select * from table(ut_runner.get_suites_info()) where item_type = 'UT_SUITE';
27+
```
28+
29+
To get list of all tests for test suite `TEST_STUFF` in current user schema
30+
```sql
31+
select * from table(ut_runner.get_suites_info(USER, 'TEST_STUFF')) where item_type = 'UT_TEST';
32+
```
33+
34+
To get a full information about suite `TEST_STUFF` including suite description, all contexts and tests in a suite
35+
```sql
36+
select * from table(ut_runner.get_suites_info(USER, 'TEST_STUFF')) where item_type = 'UT_TEST';
37+
```
38+
39+
## Checking if schema contains tests
40+
41+
Function `ut_runner.has_suites(a_owner)` returns boolean value indicating if given schema contains test suites.
42+
43+
Example:
44+
```sql
45+
begin
46+
if ut_runner.has_suites(USER) then
47+
dbms_output.put_line( 'User '||USER||' owns test suites' );
48+
else
49+
dbms_output.put_line( 'User '||USER||' does not own test suites' );
50+
end if;
51+
end;
52+
```
53+
54+
## Checking if package is a test suite
55+
56+
Function `ut_runner.is_suite(a_owner, a_package_name) ` returns boolean value indicating if given package is a test suites.
57+
58+
Example:
59+
```sql
60+
begin
61+
if ut_runner.is_suite(USER,'TEST_STUFF') then
62+
dbms_output.put_line( 'Package '||USER||'.TEST_STUFF is a test suite' );
63+
else
64+
dbms_output.put_line( 'Package '||USER||'.TEST_STUFF is not a test suite' );
65+
end if;
66+
end;
67+
```
68+
69+
## Checking if procedure is a test within a suite
70+
71+
Function `ut_runner.is_test(a_owner, a_package_name, a_procedure_name) ` returns boolean value indicating if given package is a test suites.
72+
73+
Example:
74+
```sql
75+
begin
76+
if ut_runner.is_test(USER,'TEST_STUFF','A_TEST_TO_CHECK_STUFF') then
77+
dbms_output.put_line( 'Procedure '||USER||'.TEST_STUFF.A_TEST_TO_CHECK_STUFF is a test' );
78+
else
79+
dbms_output.put_line( 'Procedure '||USER||'.TEST_STUFF.A_TEST_TO_CHECK_STUFF is not a test' );
80+
end if;
81+
end;
82+
```
83+

docs/userguide/running-unit-tests.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Running tests
22

3-
The utPLSQL framework provides two main entry points to run unit tests from within the database:
3+
utPLSQL framework provides two main entry points to run unit tests from within the database:
44

55
- `ut.run` procedures and functions
66
- `ut_runner.run` procedures
77

88
These two entry points differ in purpose and behavior.
9-
Most of the time you will want to use `ut.run` as `ut_runner` is designed for API integration and does not output the results to the screen directly.
9+
Most of the time you will want to use `ut.run` as `ut_runner.run` is designed for API integration and does not display the results to the screen.
1010

1111
# Running from CI servers and command line
1212

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nav:
1818
- Expectations: userguide/expectations.md
1919
- Advanced data comparison: userguide/advanced_data_comparison.md
2020
- Running unit tests: userguide/running-unit-tests.md
21+
- Querying for test suites: userguide/querying_suites.md
2122
- Testing best pracitces: userguide/best-practices.md
2223
- Upgrade utPLSQL: userguide/upgrade.md
2324
- Reporting:

source/api/ut_runner.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ create or replace package body ut_runner is
165165
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
166166
end;
167167

168-
function get_suites_info(a_owner varchar2, a_package_name varchar2 := null) return ut_suite_items_info pipelined is
168+
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined is
169169
l_cursor sys_refcursor;
170170
l_results ut_suite_items_info;
171171
c_bulk_limit constant integer := 10;
172172
begin
173-
l_cursor := ut_suite_manager.get_suites_info( a_owner, a_package_name );
173+
l_cursor := ut_suite_manager.get_suites_info( nvl(a_owner,sys_context('userenv', 'current_schema')), a_package_name );
174174
loop
175175
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
176176
for i in 1 .. l_results.count loop

source/api/ut_runner.pks

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ create or replace package ut_runner authid current_user is
9191
/**
9292
* Returns a pipelined collection containing information about unit test suites and the tests contained in them
9393
*
94-
* @param a_owner owner of unit tests to retrieve
95-
* @param a_package_name optional name of unit test package to retrieve, if NULLm all unit test packages are returned
94+
* @param a_owner owner of unit tests to retrieve (optional), if NULL, current schema is used
95+
* @param a_package_name name of unit test package to retrieve (optional), if NULL all unit test packages are returned
9696
* @return ut_suite_items_info table of objects
9797
*/
98-
function get_suites_info(a_owner varchar2, a_package_name varchar2 := null) return ut_suite_items_info pipelined;
98+
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined;
9999

100100

101101
/**

test/api/test_ut_runner.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ end;';
284284
'dummy_test_package.some_dummy_test_procedure' path, 0 disabled_flag
285285
from dual;
286286
--Act
287-
open l_actual for select * from table(ut3.ut_runner.get_suites_info('UT3_TESTER','DUMMY_TEST_PACKAGE'));
287+
open l_actual for select * from table(ut3.ut_runner.get_suites_info(NULL,'DUMMY_TEST_PACKAGE'));
288288
--Assert
289289
ut.expect(l_actual).to_equal(l_expected);
290290
end;

0 commit comments

Comments
 (0)