Skip to content

Commit de6552a

Browse files
authored
Merge pull request #1203 from utPLSQL/feature/call_tests_by_part_of_name
Add ability to run tests by part of a name.
2 parents 6751290 + 647b830 commit de6552a

21 files changed

Lines changed: 1348 additions & 359 deletions

docs/userguide/querying_suites.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ To get a full information about suite `TEST_STUFF` including suite description,
3939
select * from table(ut_runner.get_suites_info(USER, 'TEST_STUFF')) where item_type = 'UT_TEST';
4040
```
4141

42+
To get a full information about suites that have a path like `ut3:tests.test_package_*` including suite description, all contexts and tests in a suite
43+
```sql
44+
select * from table(ut_runner.get_suites_info('ut3:tests.test_package_*') where item_type = 'UT_TEST';
45+
```
46+
47+
To get a full information about suites that have object name like `test_package_*` including suite description, all contexts and tests in a suite
48+
```sql
49+
select * from table(ut_runner.get_suites_info('test_package_*'));
50+
```
51+
4252
## Checking if schema contains tests
4353

4454
Function `ut_runner.has_suites(a_owner)` returns boolean value indicating if given schema contains test suites.

docs/userguide/running-unit-tests.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ The **functions** can only be used in SELECT statements. They execute the specif
4545
## ut.run procedures
4646

4747
The examples below illustrate different ways and options to invoke `ut.run` procedures.
48+
You can use a wildcard character `*` to call tests by part of their name or to call tests that are located on paths matched by part of path string.
49+
Wildcard character can be placed anywhere on the path and can occur mutliple times.
50+
Schema name cannot contain a wildcard character whether is in a suitepath call or call by object name.
4851

4952
```sql
5053
alter session set current_schema=hr;
@@ -75,6 +78,23 @@ end;
7578
Executes all tests from all packages that are on the _com.my_org.my_project_ suitepath.
7679
Check the [annotations documentation](annotations.md) to find out about suitepaths and how they can be used to organize test packages for your project.
7780

81+
```sql
82+
set serveroutput on
83+
begin
84+
ut.run('hr:com*');
85+
end;
86+
```
87+
88+
Executes all tests in schema `hr` from all packages that are on suitepath starting with `com`.
89+
90+
```sql
91+
set serveroutput on
92+
begin
93+
ut.run('hr:co*.my_*.my_*');
94+
end;
95+
```
96+
97+
Executes all tests in schema `hr` from all packages that starting with `my_` and all tests starting with `my_*` that are on suitepath starting with `co` .
7898

7999
```sql
80100
set serveroutput on
@@ -124,6 +144,22 @@ Using a list of items to execute allows you to execute a fine-grained set of tes
124144

125145
List can be passed as a comma separated list or a list of *ut_varchar2_list objects* or as a list within ut_varchar2_list.
126146

147+
```sql
148+
set serveroutput on
149+
begin
150+
ut.run('hr.test*');
151+
end;
152+
```
153+
Executes all tests in schema `hr` located in packages starting with name `test`.
154+
155+
```sql
156+
set serveroutput on
157+
begin
158+
ut.run('hr.test_apply_bonus.bonus_*');
159+
end;
160+
```
161+
Executes test procedures with names starting with `bonus` in package `hr.test_apply_bonus` .
162+
127163

128164
**Note:**
129165

source/api/ut_runner.pkb

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,14 @@ create or replace package body ut_runner is
172172
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
173173
end;
174174

175-
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined is
175+
function get_suites_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined is
176176
l_cursor sys_refcursor;
177177
l_results ut_suite_items_info;
178178
c_bulk_limit constant integer := 100;
179+
l_path varchar2(4000) := nvl(a_owner,sys_context('userenv', 'current_schema'))||'.'||nvl(a_package_name,'*');
179180
begin
180-
l_cursor := ut_suite_manager.get_suites_info( nvl(a_owner,sys_context('userenv', 'current_schema')), a_package_name );
181+
182+
l_cursor := ut_suite_manager.get_suites_info(ut_varchar2_list(l_path));
181183
loop
182184
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
183185
for i in 1 .. l_results.count loop
@@ -189,6 +191,26 @@ create or replace package body ut_runner is
189191
return;
190192
end;
191193

194+
function get_suites_info(a_path varchar2 := null) return ut_suite_items_info pipelined is
195+
l_cursor sys_refcursor;
196+
l_results ut_suite_items_info;
197+
c_bulk_limit constant integer := 100;
198+
i pls_integer;
199+
begin
200+
l_cursor := ut_suite_manager.get_suites_info(ut_varchar2_list(nvl(a_path,sys_context('userenv', 'current_schema'))));
201+
loop
202+
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
203+
i := l_results.first;
204+
while (i is not null) loop
205+
pipe row (l_results(i));
206+
i := l_results.next(i);
207+
end loop;
208+
exit when l_cursor%notfound;
209+
end loop;
210+
close l_cursor;
211+
return;
212+
end;
213+
192214
function is_test(a_owner varchar2, a_package_name varchar2, a_procedure_name varchar2) return boolean is
193215
l_result boolean := false;
194216
begin
@@ -243,37 +265,6 @@ create or replace package body ut_runner is
243265
end loop;
244266
end;
245267

246-
function hash_suite_path(a_path varchar2, a_random_seed positiven) return varchar2 is
247-
l_start_pos pls_integer := 1;
248-
l_end_pos pls_integer := 1;
249-
l_result varchar2(4000);
250-
l_item varchar2(4000);
251-
l_at_end boolean := false;
252-
begin
253-
if a_random_seed is null then
254-
l_result := a_path;
255-
end if;
256-
if a_path is not null then
257-
loop
258-
l_end_pos := instr(a_path,'.',l_start_pos);
259-
if l_end_pos = 0 then
260-
l_end_pos := length(a_path)+1;
261-
l_at_end := true;
262-
end if;
263-
l_item := substr(a_path,l_start_pos,l_end_pos-l_start_pos);
264-
if l_item is not null then
265-
l_result :=
266-
l_result ||
267-
ut_utils.get_hash( to_char( dbms_utility.get_hash_value( l_item, 1, a_random_seed ) ) );
268-
end if;
269-
exit when l_at_end;
270-
l_result := l_result || chr(0);
271-
l_start_pos := l_end_pos + 1;
272-
end loop;
273-
end if;
274-
return l_result;
275-
end;
276-
277268
procedure coverage_start(a_coverage_run_id raw) is
278269
begin
279270
ut_coverage.coverage_start(a_coverage_run_id);

source/api/ut_runner.pks

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ create or replace package ut_runner authid current_user is
104104
* @param a_package_name name of unit test package to retrieve (optional), if NULL all unit test packages are returned
105105
* @return ut_suite_items_info table of objects
106106
*/
107-
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined;
107+
function get_suites_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined;
108+
109+
/**
110+
* Returns a pipelined collection containing information about unit test suites and the tests contained in them
111+
*
112+
* @param a_path a path from which we lookg for object or suite
113+
*/
114+
function get_suites_info(a_path varchar2 := null) return ut_suite_items_info pipelined;
108115

109116

110117
/**
@@ -144,11 +151,6 @@ create or replace package ut_runner authid current_user is
144151
*/
145152
function get_reporters_list return tt_reporters_info pipelined;
146153

147-
/*
148-
* Returns a hash value of suitepath based on input path and random seed
149-
*/
150-
function hash_suite_path(a_path varchar2, a_random_seed positiven) return varchar2;
151-
152154
procedure coverage_start(a_coverage_run_id raw);
153155

154156
procedure coverage_stop;

source/core/types/ut_path_item.tpb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
create or replace type body ut_path_item as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2021 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2) return self as result is
19+
begin
20+
self.schema_name := schema_name;
21+
self.object_name := object_name;
22+
self.procedure_name := procedure_name;
23+
return;
24+
end;
25+
26+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2,suite_path varchar2) return self as result is
27+
begin
28+
self.schema_name := schema_name;
29+
self.suite_path := suite_path;
30+
return;
31+
end;
32+
33+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2,suite_path varchar2) return self as result is
34+
begin
35+
self.schema_name := schema_name;
36+
self.object_name := object_name;
37+
self.procedure_name := procedure_name;
38+
self.suite_path := suite_path;
39+
return;
40+
end;
41+
end;
42+
/

source/core/types/ut_path_item.tps

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
create or replace type ut_path_item as object (
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2021 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
schema_name varchar2(4000),
19+
object_name varchar2(250),
20+
procedure_name varchar2(250),
21+
suite_path varchar2(4000),
22+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2) return self as result,
23+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, suite_path varchar2) return self as result,
24+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2,suite_path varchar2) return self as result
25+
)
26+
/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
create or replace type ut_path_items as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2021 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
table of ut_path_item
19+
/

0 commit comments

Comments
 (0)