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

Skip to content

Commit 3a66021

Browse files
committed
tmp
1 parent 8264e12 commit 3a66021

6 files changed

Lines changed: 99 additions & 20 deletions

File tree

docs/userguide/coverage.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,25 @@ The report allow to navigate to every source and inspect line by line coverage.
5252
![Coverage Details page](../images/coverage_html_details.png)
5353

5454

55-
## Coverage reporting options
56-
By default the database schema/schemes containing the tests that were executed during the run, are fully reported by coverage reporter.
57-
All valid unit tests are excluded from the report regardless if they were invoked or not. This way the coverage report is not affected by presence of tests and contains only the tested code.
55+
### Coverage reporting options
56+
57+
There are two ways to gather code coverage.
58+
- You can gather coverage for a particular database schema/schemes
59+
- You can gather coverage on project files deployed to database as database objects (packages, functions, procedures ect.)
60+
61+
Those two options are mutually exclusive and should not be mixed. Depending on the parameters you pass you will be using one option or the other.
62+
63+
When using one of coverage reporters and no additional options are provided, coverage is gathered on a schema level.
64+
The database schema/schemes containing the tests that were executed during the run, will be reported by coverage reporter.
65+
66+
All unit tests are excluded from the report regardless if they were invoked or not.
67+
This way the coverage report is not affected by presence of tests and contains only the tested code.
5868

5969
The default behavior of coverage reporters can be altered, depending on your needs.
6070

61-
### Including/excluding objects in coverage reports
71+
### Coverage on schema
72+
73+
#### Filtering objects in coverage reports
6274
The most basic options are the include/exclude objects lists.
6375
You may specify both include and exclude objects lists to specify which objects are to be included in the report and which are to be excluded.
6476
Both of those options are meant to be used to narrow down the scope of unit test runs, that is broad by default.
@@ -77,11 +89,11 @@ Executes test `test_award_bonus` and gather on all objects in schema `ut3_user`
7789

7890
You can also combine the parameters and both will be applied.
7991

80-
### Defining different schema names
92+
#### Defining different schema names
8193
In some architectures, you might end up in a situation, where your unit tests exist in a different schema than the tested code.
8294
This is not the default or recommended approach but is supporter by utPLSQL.
8395
In such scenarios, you would probably have a separate database schema to hold unit tests and a separate schema/schemes to hold the tested code.
84-
Since by default, coverage reporting is done on the schema/schemes that the invoked tests are on, the code will not be included in coverage report as it is in a different schema than the invoked tests.
96+
Since by default, coverage reporting is done on the schema/schemes that the invoked tests are on, the code will not be included in coverage report as it is in a different schema.
8597

8698
In this situation you need to provide list of schema names that the tested code is in. This option overrides the default schema names for coverage.
8799

@@ -92,7 +104,7 @@ exec ut.run('ut3_user.test_award_bonus', ut_coverage_html_reporter(), a_coverage
92104
Executes test `test_award_bonus` in schema `ut3_user` and gather coverage for that execution on all non `unit-test` objects from schema `usr`.
93105

94106
You can combine schema names with include/exclude parameters and all will be applied.
95-
The `a_coverage_schemes` parameter takes precedence however, so if include list contains objects from other schemes, that will not be considered.
107+
Keep in mind that the if you use `a_include_list` the `a_coverage_schemes` will simply be ignored.
96108

97109
Example:
98110
```sql
@@ -106,16 +118,21 @@ begin
106118
);
107119
end;
108120
```
121+
109122
Executes test `test_award_bonus` in schema `ut3_user` and gather coverage for that execution on `award_bonus` object from schema `usr`. The exclude list is of no relevance as it is not overlapping with include list.
110123

111-
### Working with projects and project files
112-
Both `sonar` and `coveralls` are utilities that are more project-oriented than database-centric. They report statistics and coverage for project files in version control system.
113-
Nowadays, most of database projects are moving away from database-centric approach towards project/product-centric approach.
124+
125+
### Coverage on project
126+
127+
Both `Sonar` and `Coveralls` are utilities that are project-oriented and are not database-centric.
128+
They report statistics and coverage for project files in version control system and are not aware of database at all.
114129
Coverage reporting of utPLSQL allows you to perform code coverage analysis for your project files.
115-
This feature is supported by all build-in coverage reporting formats.
130+
utPLSQL is able to map code coverage from your database code to your project files.
116131

132+
When using project based approach, utPLSQL will report coverage only for project-files that were successfully mapped into database objects.
133+
117134
When using this invocation syntax, coverage is only reported for the provided files, so using project files as input for coverage is also a way of limiting the scope of coverage analysis.
118-
This syntax also allows usage of `a_include_object_list` and `a_exclude_object_list` as optional parameters to filter the scope of analysis.
135+
This syntax also allows usage of `a_exclude_object_list` as optional parameters to filter the scope of analysis based on database objects.
119136

120137

121138
**Reporting using externally provided file mapping**
@@ -158,7 +175,7 @@ begin
158175
ut.run(
159176
'usr',
160177
ut_coverage_html_reporter(),
161-
a_source_files => ut_varchar2_list('sources/hr/award_bonus.prc','sources/hr/betwnstr.fnc')
178+
a_source_files => ut_varchar2_list('sources/hr.award_bonus.prc','sources/hr.betwnstr.fnc')
162179
);
163180
end;
164181
```

source/core/ut_file_mapper.pkb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ create or replace package body ut_file_mapper is
8484
l_object_type_key varchar2(4000);
8585
l_object_type varchar2(4000);
8686
l_object_owner varchar2(4000);
87+
l_file_path varchar2(32767);
8788
begin
8889
if a_file_paths is not null then
8990
l_key_values := to_hash_table(l_file_to_object_type_mapping);
9091
l_mappings := ut_file_mappings();
9192

9293
for i in 1 .. a_file_paths.count loop
93-
l_object_type_key := upper(regexp_substr(a_file_paths(i), l_regex_pattern, 1, 1, 'i', l_object_type_subexpression));
94+
l_file_path := replace(a_file_paths(i),'\','/');
95+
l_object_type_key := upper(regexp_substr(l_file_path, l_regex_pattern, 1, 1, 'i', l_object_type_subexpression));
9496
if l_key_values.exists(l_object_type_key) then
9597
l_object_type := upper(l_key_values(l_object_type_key));
9698
else
@@ -99,13 +101,13 @@ create or replace package body ut_file_mapper is
99101

100102
l_object_owner := coalesce(
101103
upper(a_object_owner),
102-
upper(regexp_substr(a_file_paths(i), l_regex_pattern, 1, 1, 'i', l_object_owner_subexpression)),
104+
upper(regexp_substr(l_file_path, l_regex_pattern, 1, 1, 'i', l_object_owner_subexpression)),
103105
sys_context('USERENV', 'CURRENT_SCHEMA'));
104106

105107
l_mapping := ut_file_mapping(
106108
file_name => a_file_paths(i),
107109
object_owner => l_object_owner,
108-
object_name => upper(regexp_substr(a_file_paths(i), l_regex_pattern, 1, 1, 'i', l_object_name_subexpression)),
110+
object_name => upper(regexp_substr(l_file_path, l_regex_pattern, 1, 1, 'i', l_object_name_subexpression)),
109111
object_type => l_object_type
110112
);
111113
l_mappings.extend();

source/core/ut_file_mapper.pks

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ create or replace package ut_file_mapper authid current_user is
1616
limitations under the License.
1717
*/
1818

19-
gc_file_mapping_regex constant varchar2(100) := '.*(\\|\/)((\w+)\.)?(\w+)\.(\w{3})';
20-
gc_regex_owner_subexpression constant positive := 3;
21-
gc_regex_name_subexpression constant positive := 4;
22-
gc_regex_type_subexpression constant positive := 5;
19+
gc_file_mapping_regex constant varchar2(100) := '.*/((\w+)\.)?(\w+)\.(\w{3})$';
20+
gc_regex_owner_subexpression constant positive := 2;
21+
gc_regex_name_subexpression constant positive := 3;
22+
gc_regex_type_subexpression constant positive := 4;
2323

2424
function default_file_to_obj_type_map return ut_key_value_pairs;
2525

test/core/test_file_mapper.pkb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
create or replace package body test_file_mapper is
2+
3+
procedure default_mappings is
4+
l_actual ut3.ut_file_mappings;
5+
l_expected ut3.ut_file_mappings;
6+
begin
7+
--Arrange
8+
l_expected := ut3.ut_file_mappings(
9+
ut3.ut_file_mapping('C:\tests\helpers\core.pkb',USER,'CORE','PACKAGE BODY'),
10+
ut3.ut_file_mapping('tests/helpers/test_file_mapper.pkb',USER,'TEST_FILE_MAPPER','PACKAGE BODY')
11+
);
12+
--Act
13+
l_actual := ut3.ut_file_mapper.build_file_mappings(
14+
ut3.ut_varchar2_list(
15+
'C:\tests\helpers\core.pkb',
16+
'tests/helpers/test_file_mapper.pkb'
17+
)
18+
);
19+
--Assert
20+
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
21+
end;
22+
23+
procedure specific_owner is
24+
l_actual ut3.ut_file_mappings;
25+
l_expected ut3.ut_file_mappings;
26+
begin
27+
--Arrange
28+
l_expected := ut3.ut_file_mappings(
29+
ut3.ut_file_mapping('C:\source\core\types\ut_file_mapping.tpb','UT3','UT_FILE_MAPPING','TYPE BODY'),
30+
ut3.ut_file_mapping('source/core/ut_file_mapper.pkb','UT3','UT_FILE_MAPPER','PACKAGE BODY')
31+
);
32+
--Act
33+
l_actual := ut3.ut_file_mapper.build_file_mappings(
34+
'UT3',
35+
ut3.ut_varchar2_list(
36+
'C:\source\core\types\ut_file_mapping.tpb',
37+
'source/core/ut_file_mapper.pkb'
38+
)
39+
);
40+
--Assert
41+
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
42+
end;
43+
44+
end;
45+
/

test/core/test_file_mapper.pks

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
create or replace package test_file_mapper is
2+
3+
--%suite(file_mapper)
4+
--%suitepath(utplsql.core)
5+
6+
--%test(Maps file paths into database objects using default mappings)
7+
procedure default_mappings;
8+
9+
--%test(Used specified object owner to perform mapping when files have no owner indication)
10+
procedure specific_owner;
11+
12+
end;
13+
/

test/install_tests.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ whenever oserror exit failure rollback
2424
@@core/annotations/test_annotation_manager.pks
2525
@@core/expectations/test_matchers.pks
2626
@@core/test_output_buffer.pks
27+
@@core/test_file_mapper.pks
2728
@@core/test_suite_manager.pks
2829
@@core/reporters/test_coverage.pks
2930
@@core/reporters/test_coverage/test_coverage_sonar_reporter.pks
@@ -56,6 +57,7 @@ whenever oserror exit failure rollback
5657
@@core/annotations/test_annotation_manager.pkb
5758
@@core/expectations/test_matchers.pkb
5859
@@core/test_output_buffer.pkb
60+
@@core/test_file_mapper.pkb
5961
@@core/test_suite_manager.pkb
6062
@@core/reporters/test_coverage.pkb
6163
@@core/reporters/test_coverage/test_coverage_sonar_reporter.pkb

0 commit comments

Comments
 (0)