8000 Add ability to run tests by part of a name. by lwasylow · Pull Request #1203 · utPLSQL/utPLSQL · GitHub
[go: up one dir, main page]

Skip to content

Add ability to run tests by part of a name. #1203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
86d4d0a
Initial check-in.
lwasylow Mar 18, 2022
f1f6d71
Tidy up code to make sure we got distinct set of expanded tests.
lwasylow Mar 19, 2022
1454221
Adding extra fields.
lwasylow Mar 23, 2022
ce4df28
Stage 3. Fixing error calls.
lwasylow Mar 29, 2022
273962b
Fixing issue with a non visible tests.
lwasylow Mar 29, 2022
a753e66
Fixing ORA-600
lwasylow Mar 30, 2022
0d8d34d
Cleanup Phase1.
lwasylow Mar 30, 2022
95ddec1
Adding tests.
lwasylow Mar 31, 2022
83dbdaa
Updating documentation.
lwasylow Mar 31, 2022
52c0307
Addresing sonar issues
lwasylow Mar 31, 2022
8f8d257
Extra tests and cleanup of old code.
lwasylow Apr 1, 2022
12be123
Adding extra tests
lwasylow Apr 1, 2022
d5ee6ca
Updating SQL to expand paths and extract suites.
lwasylow Apr 1, 2022
2db8d63
Addressing issue with reconstruct_cache knocking off other levels.
lwasylow Apr 6, 2022
d3396fe
Update tests for random order
lwasylow Apr 7, 2022
02d41a6
Removing a hash function from api into utils package which is more su…
lwasylow Apr 7, 2022
274d80a
Fixing ordering
lwasylow Apr 7, 2022
3937737
Fixing a documentation
lwasylow Apr 7, 2022
9296f38
Fixing inde 8000 nt
lwasylow Apr 7, 2022
6ff7f38
Peer review changes
lwasylow Apr 12, 2022
ee7a98b
Moving a SQL to be more readable.
lwasylow Apr 12, 2022
a53cefa
Apply suggestions from code review
jgebal Apr 13, 2022
011970f
Apply suggestions from code review
jgebal Apr 13, 2022
71e07f9
Merge remote-tracking branch 'origin/develop' into feature/call_tests…
jgebal Apr 15, 2022
221c2de
Address issue of not recognizing a correct nested level of suitepath.
lwasylow Apr 16, 2022
870cfe4
Merge branch 'feature/call_tests_by_part_of_name' of https://github.c…
lwasylow Apr 16, 2022
51439d8
Update documentation
lwasylow Apr 16, 2022
0fc7ff6
Fixing issue where parition by only path caused a duplicate level 1 a…
lwasylow Apr 16, 2022
647b830
Fixed issue with suites getting duplicated when running tests across …
jgebal Apr 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/userguide/querying_suites.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ To get a full information about suite `TEST_STUFF` including suite description,
select * from table(ut_runner.get_suites_info(USER, 'TEST_STUFF')) where item_type = 'UT_TEST';
```

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
```sql
select * from table(ut_runner.get_suites 8000 _info('ut3:tests.test_package_*') where item_type = 'UT_TEST';
```

To get a full information about suites that have object name like `test_package_*` including suite description, all contexts and tests in a suite
```sql
select * from table(ut_runner.get_suites_info('test_package_*'));
```

## Checking if schema contains tests

Function `ut_runner.has_suites(a_owner)` returns boolean value indicating if given schema contains test suites.
Expand Down
36 changes: 36 additions & 0 deletions docs/userguide/running-unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ The **functions** can only be used in SELECT statements. They execute the specif
## ut.run procedures

The examples below illustrate different ways and options to invoke `ut.run` procedures.
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.
Wildcard character can be placed anywhere on the path and can occur mutliple times.
Schema name cannot contain a wildcard character whether is in a suitepath call or call by object name.

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

```sql
set serveroutput on
begin
ut.run('hr:com*');
end;
```

Executes all tests in schema `hr` from all packages that are on suitepath starting with `com`.

```sql
set serveroutput on
begin
ut.run('hr:co*.my_*.my_*');
end;
```

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` .

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

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.

```sql
set serveroutput on
begin
ut.run('hr.test*');
end;
```
Executes all tests in schema `hr` located in packages starting with name `test`.

```sql
set serveroutput on
begin
ut.run('hr.test_apply_bonus.bonus_*');
end;
```
Executes test procedures with names starting with `bonus` in package `hr.test_apply_bonus` .


**Note:**

Expand Down
57 changes: 24 additions & 33 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ create or replace package body ut_runner is
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
end;

function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined is
function get_suites_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined is
l_cursor sys_refcursor;
l_results ut_suite_items_info;
c_bulk_limit constant integer := 100;
l_path varchar2(4000) := nvl(a_owner,sys_context('userenv', 'current_schema'))||'.'||nvl(a_package_name,'*');
begin
l_cursor := ut_suite_manager.get_suites_info( nvl(a_owner,sys_context('userenv', 'current_schema')), a_package_name );

l_cursor := ut_suite_manager.get_suites_info(ut_varchar2_list(l_path));
loop
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
for i in 1 .. l_results.count loop
Expand All @@ -189,6 +191,26 @@ create or replace package body ut_runner is
return;
end;

function get_suites_info(a_path varchar2 := null) return ut_suite_items_info pipelined is
l_cursor sys_refcursor;
l_results ut_suite_items_info;
c_bulk_limit constant integer := 100;
i pls_integer;
begin
l_cursor := ut_suite_manager.get_suites_info(ut_varchar2_list(nvl(a_path,sys_context('userenv', 'current_schema'))));
loop
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
i := l_results.first;
while (i is not null) loop
pipe row (l_results(i));
i := l_results.next(i);
end loop;
exit when l_cursor%notfound;
end loop;
close l_cursor;
return;
end;

function is_test(a_owner varchar2, a_package_name varchar2, a_procedure_name varchar2) return boolean is
l_result boolean := false;
begin
Expand Down Expand Up @@ -243,37 +265,6 @@ create or replace package body ut_runner is
end loop;
end;

function hash_suite_path(a_path varchar2, a_random_seed positiven) return varchar2 is
l_start_pos pls_integer := 1;
l_end_pos pls_integer := 1;
l_result varchar2(4000);
l_item varchar2(4000);
l_at_end boolean := false;
begin
if a_random_seed is null then
l_result := a_path;
end if;
if a_path is not null then
loop
l_end_pos := instr(a_path,'.',l_start_pos);
if l_end_pos = 0 then
l_end_pos := length(a_path)+1;
l_at_end := true;
end if;
l_item := substr(a_path,l_start_pos,l_end_pos-l_start_pos);
if l_item is not null then
l_result :=
l_result ||
ut_utils.get_hash( to_char( dbms_utility.get_hash_value( l_item, 1, a_random_seed ) ) );
end if;
exit when l_at_end;
l_result := l_result || chr(0);
l_start_pos := l_end_pos + 1;
end loop;
end if;
return l_result;
end;

procedure coverage_start(a_coverage_run_id raw) is
begin
ut_coverage.coverage_start(a_coverage_run_id);
Expand Down
14 changes: 8 additions & 6 deletions source/api/ut_runner.pks
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ create or replace package ut_runner authid current_user is
* @param a_package_name name of unit test package to retrieve (optional), if NULL all unit test packages are returned
* @return ut_suite_items_info table of objects
*/
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined;
function get_suites_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined;

/**
* Returns a pipelined collection containing information about unit test suites and the tests contained in them
*
* @param a_path a path from which we lookg for object or suite
*/
function get_suites_info(a_path varchar2 := null) return ut_suite_items_info pipelined;


/**
Expand Down Expand Up @@ -144,11 +151,6 @@ create or replace package ut_runner authid current_user is
*/
function get_reporters_list return tt_reporters_info pipelined;

/*
* Returns a hash value of suitepath based on input path and random seed
*/
function hash_suite_path(a_path varchar2, a_random_seed positiven) return varchar2;

procedure coverage_start(a_coverage_run_id raw);

procedure coverage_stop;
Expand Down
42 changes: 42 additions & 0 deletions source/core/types/ut_path_item.tpb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
create or replace type body ut_path_item as
/*
utPLSQL - Version 3
Copyright 2016 - 2021 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
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
begin
self.schema_name := schema_name;
self.object_name := object_name 10000 ;
self.procedure_name := procedure_name;
return;
end;

constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2,suite_path varchar2) return self as result is
begin
self.schema_name := schema_name;
self.suite_path := suite_path;
return;
end;

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
begin
self.schema_name := schema_name;
self.object_name := object_name;
self.procedure_name := procedure_name;
self.suite_path := suite_path;
return;
end;
end;
/
26 changes: 26 additions & 0 deletions source/core/types/ut_path_item.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
create or replace type ut_path_item as object (
/*
utPLSQL - Version 3
Copyright 2016 - 2021 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
schema_name varchar2(4000),
object_name varchar2(250),
procedure_name varchar2(250),
suite_path varchar2(4000),
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,
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, suite_path varchar2) return self as result,
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
)
/
19 changes: 19 additions & 0 deletions source/core/types/ut_path_items.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
create or replace type ut_path_items as
/*
utPLSQL - Version 3
Copyright 2016 - 2021 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
table of ut_path_item
/
Loading
0