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

Skip to content

Commit 7cca6b4

Browse files
committed
Update of coverage.md
1 parent 3bdb9d0 commit 7cca6b4

1 file changed

Lines changed: 53 additions & 20 deletions

File tree

docs/userguide/coverage.md

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ If you have `execute` privilege on the code that is being tested, but do not hav
3232
If you have `execute` privilege only on the unit tests, but do not have `execute` privilege on the code that is being tested, the code will not be reported by coverage - as if it did not exist in the database.
3333
If the code that is being tested is compiled as NATIVE, the code coverage will not be reported as well.
3434

35-
## Running unit tests with coverage
36-
Using the code coverage functionality is as easy as using any other [reporter](reporters.md) for the utPLSQL test-run. You just run your tests from your preferred SQL tool and save the reporter results to a file.
37-
All you need to do is pass the constructor of the reporter to the `ut.run` procedure call.
35+
## Manually running unit tests with coverage
36+
Using the code coverage functionality is as easy as using any other [reporter](reporters.md) for the utPLSQL test-run. Run your tests from your preferred SQL tool and save the reporter results to a file.
37+
All you need to do, is pass the constructor of the reporter to the `ut.run` procedure call.
3838

3939
Example:
4040
```sql
41+
set serveroutput on
4142
begin
4243
ut.run(ut_coverage_html_reporter());
4344
end;
4445
/
4546
```
46-
The above command executes all unit tests in the **current schema**, gathers information about code coverage and outputs the HTML report as text into DBMS_OUTPUT.
47+
The above command executes all unit tests in the **current schema**, gathers information about code coverage for all sources in that schema and outputs the HTML report as text into DBMS_OUTPUT.
4748
The `ut_coverage_html_reporter` will produce an interactive HTML report. You can see a sample of code coverage for the utPLSQL project [here](https://utplsql.github.io/utPLSQL-coverage-html/)
4849

4950
The report provides summary information with a list of source code that should be covered.
@@ -79,14 +80,14 @@ There are two distinct ways to gather code coverage:
7980
- Coverage on project files
8081

8182
Those two options are mutually exclusive and cannot be mixed.
82-
By default, when using one of coverage reporters, coverage is gathered on schema(s).
83+
By default, when using one of coverage reporters, coverage is gathered on schema(s).
84+
The database schema(s) containing the tests that were executed during the run will be reported on by coverage reporter.
8385

8486
The parameters used to execute tests determine if utPLSQL will be using one approach or the other.
87+
If parameter `a_source_file_mappings` or `a_source_files` is provided, then coverage is gathered on project files provided, otherwise coverage is gathered on schemas.
8588

86-
The database schema(s) containing the tests that were executed during the run will be reported on by coverage reporter.
8789

8890
**Note**
89-
9091
> Regardless of the options provided, all unit test packages are excluded from the coverage report. Coverage reports provide information only about the **tested** code.
9192
9293
The default behavior of coverage reporting can be altered using invocation parameters.
@@ -131,10 +132,10 @@ exec ut.run('unit_test_schema', ut_coverage_html_reporter(), a_coverage_schemes
131132

132133
There are multiple parameters that can be used to define the scope of coverage report:
133134
- `a_source_file_mappings ( ut_file_mappings )` - map of filenames to database objects. It is used for file-based coverage - see below.
134-
- `a_include_schema_expr ( varchar(4000) )` - string of regex expression of schemas to be included in the coverage report.
135-
- `a_include_object_expr ( varchar(4000) )` - string of regex expression of objects ( without schema name ) to be included in the coverage report.
136-
- `a_exclude_schema_expr ( varchar(4000) )` - string of regex expression of schemas to be excluded from the coverage report.
137-
- `a_exclude_object_expr ( varchar(4000) )` - string of regex expression of objects to be excluded from the coverage report.
135+
- `a_include_schema_expr ( varchar(4000) )` - string of regex expression of schemas to be included in the coverage report. Case-insensitive.
136+
- `a_include_object_expr ( varchar(4000) )` - string of regex expression of objects ( without schema name ) to be included in the coverage report. Case-insensitive.
137+
- `a_exclude_schema_expr ( varchar(4000) )` - string of regex expression of schemas to be excluded from the coverage report. Case-insensitive.
138+
- `a_exclude_object_expr ( varchar(4000) )` - string of regex expression of objects ( without schema name ) to be excluded from the coverage report. Case-insensitive.
138139
- `a_coverage_schemes ( ut_varchar2_list )` - List of database schema names to gather coverage on.
139140
- `a_include_objects ( ut_varchar2_list )` - list of `[object_owner.]object_name` to be included in the coverage report.
140141
- `a_exclude_objects ( ut_varchar2_list )` - list of `[object_owner.]object_name` to be excluded from the coverage report.
@@ -164,6 +165,7 @@ end;
164165
```
165166
Will result in showing coverage for all schemas that match regular expression `^ut3_develop`
166167

168+
Example: Limiting coverage by schema regex with parameter `a_include_objects` ignored.
167169
```sql
168170
begin
169171
ut.run(ut_varchar2_list('user_1','user_2'), ut_coverage_html_reporter(),
@@ -172,37 +174,68 @@ begin
172174
end;
173175
```
174176
Will result in showing coverage for all schemas that match regular expression `^ut3_develop`.
175-
Will ignore the `a_include_objects` parameter
176177

178+
Example: Limiting coverage by object regex.
177179
```sql
178180
begin
179181
ut.run(ut_varchar2_list('user_1','user_2'), ut_coverage_html_reporter(),
180-
a_include_object_expr => 'regex123', a_include_objects => ut_varchar2_list( 'ut3_tester_helper.regex_dummy_cov' )
182+
a_include_object_expr => 'regex123'
181183
);
182184
end;
183185
```
184186
Will result in showing coverage for all objects that name match regular expression `regex123`.
185-
Will ignore the `a_include_objects` parameter.
186187

188+
Example: Limiting coverage by object regex with parameter `a_include_objects` ignored.
189+
```sql
190+
begin
191+
ut.run(ut_varchar2_list('user_1','user_2'), ut_coverage_html_reporter(),
192+
a_include_object_expr => 'utl', a_include_objects => ut_varchar2_list( 'user_2.utils_package' )
193+
);
194+
end;
195+
```
196+
Will result in showing coverage for all objects that name match regular expression `utl`.
197+
198+
Example: Limiting coverage by excluding schema with regex.
199+
```sql
200+
begin
201+
ut.run(ut_varchar2_list('user_1','user_2'), ut_coverage_html_reporter(),
202+
a_exclude_schema_expr => 'er_1$'
203+
);
204+
end;
205+
```
206+
Will result in showing coverage for objects in all schema except schemas that are matching regular expression `er_1$`
207+
208+
Example: Limiting coverage by excluding schema with regex and excluding specific object.
209+
```sql
210+
begin
211+
ut.run(ut_varchar2_list('user_1','user_2'), ut_coverage_html_reporter(),
212+
a_exclude_schema_expr => 'er_1$', a_exclude_objects => ut_varchar2_list( 'user_2.utils_package' )
213+
);
214+
end;
215+
```
216+
Will result in showing coverage for objects in all schemas except schemas that are matching regular expression `er_1$`
217+
Will also exclude object `user_2.utils_package` from coverage report
218+
219+
Example: Limiting coverage by excluding objects with regex.
187220
```sql
188221
begin
189222
ut.run(ut_varchar2_list('user_1','user_2'), ut_coverage_html_reporter(),
190-
a_exclude_schema_expr => '^ut3_tester', a_exclude_objects => ut_varchar2_list( 'regex_dummy_cov' )
223+
a_exclude_object_expr => 'utl'
191224
);
192225
end;
193226
```
194-
Will result in showing coverage for objects in all schema except schemas that are matching regular expression `^ut3_tester`
195-
Will ignore exclusion defined by parameter `a_exclude_objects`
227+
Will result in showing coverage for all objects that name is not matching regular expression `utl`.
196228

229+
Example: Limiting coverage by excluding objects with regex with parameter `a_exclude_objects` ignored.
197230
```sql
198231
begin
199232
ut.run(ut_varchar2_list('user_1','user_2'), ut_coverage_html_reporter(),
200-
a_exclude_object_expr => 'regex123', a_exclude_objects => ut_varchar2_list( 'regex_dummy_cov' )
233+
a_exclude_object_expr => 'utl', a_exclude_objects => ut_varchar2_list( 'user_2.utils_package' )
201234
);
202235
end;
203236
```
204-
Will result in showing coverage for all objects that name is not matching regular expression `regex123`.
205-
Will ignore exclusion defined by parameter `a_exclude_objects`.
237+
Will result in showing coverage for all objects that name is not matching regular expression `utl`.
238+
Will also exclude object `user_2.utils_package` from coverage report
206239

207240

208241
Example: Limiting coverage by object name, for tested code located in the same schema as the unit tests.

0 commit comments

Comments
 (0)