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

Skip to content

Commit 4f83357

Browse files
committed
Added 12.2 Coverage
Update block to be called from dynamic sql to avoid a compilation issues. Updated documentation
1 parent d77cf9a commit 4f83357

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

docs/userguide/coverage.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If you have `execute` privilege on the code that are tested, but do not have `cr
2929
If you have `execute` privilege only on the unit tests, but do not have `execute` privilege on the code that is tested, the code will not be reported by coverage - as if it did not exist in the database.
3030
If the code that is testes is complied as NATIVE, the code coverage will not be reported as well.
3131

32-
## Running unite tests with coverage
32+
## Running unit tests with coverage
3333
Using code coverage functionality is as easy as using any other [reporter](reporters.md) for utPLSQL project. All you need to do is run your tests from your preferred SQL tool and save the outcomes of reporter to a file.
3434
All you need to do, is pass the constructor of the reporter to your `ut.run`
3535

@@ -40,6 +40,8 @@ begin
4040
end;
4141
/
4242
```
43+
44+
4345
Executes all unit tests in current schema, gather information about code coverage and output the html text into DBMS_OUTPUT.
4446
The `ut_coverage_html_reporter` will produce a interactive HTML report. You may see a sample of code coverage for utPLSQL project [here](https://utplsql.github.io/utPLSQL-coverage-html/)
4547

@@ -52,6 +54,20 @@ The report allow to navigate to every source and inspect line by line coverage.
5254
![Coverage Details page](../images/coverage_html_details.png)
5355

5456

57+
#### Oracle 12.2 block coverage.
58+
In Oracle 12.2 new functionality was released which supports native [block coverage](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/arpls/DBMS_PLSQL_CODE_COVERAGE.html#GUID-55A9E502-9EC2-4118-B292-DC79E6DC465E).
59+
This has been enabled in utPLSQL code coverage as a separate option. It can be invoked by passing a argument a_coverage_type with value 'block'. By default profiler option is enabled ('proftab').
60+
61+
Example:
62+
```sql
63+
begin
64+
ut.run(ut_coverage_html_reporter(),a_coverage_type => 'block');
65+
end;
66+
/
67+
```
68+
69+
In this mode html reporter will show additionally number of lines that been partially covered and highlight them in orange. Number of blocks in code, blocks covered and missed.
70+
5571
## Coverage reporting options
5672
By default the database schema/schemes containing the tests that were executed during the run, are fully reported by coverage reporter.
5773
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.

source/core/coverage/ut_coverage_helper.pkb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ create or replace package body ut_coverage_helper is
5151
end;
5252

5353
procedure coverage_start_internal(a_run_comment varchar2,a_coverage_type in varchar2) is
54-
--l_start_block varchar2(32767):= 'call dbms_plsql_code_coverage.start_coverage(run_comment => :a_run_comment)
55-
-- into :g_coverage_id';
54+
l_start_block varchar2(32767):= 'call dbms_plsql_code_coverage.start_coverage(run_comment => :a_run_comment)
55+
into :g_coverage_id';
5656
begin
5757
set_coverage_type(a_coverage_type);
5858
-- Make it dynamic to allow for block coverage.
5959
if get_coverage_type = 'block' then
60-
--execute immediate l_start_block USING IN a_run_comment, OUT g_coverage_id;
61-
g_coverage_id := dbms_plsql_code_coverage.start_coverage(run_comment => a_run_comment);
60+
execute immediate l_start_block USING IN a_run_comment, OUT g_coverage_id;
61+
--g_coverage_id := dbms_plsql_code_coverage.start_coverage(run_comment => a_run_comment);
6262
else
6363
dbms_profiler.start_profiler(run_comment => a_run_comment, run_number => g_coverage_id);
6464
coverage_pause();
@@ -105,11 +105,12 @@ create or replace package body ut_coverage_helper is
105105
end;
106106

107107
procedure coverage_stop is
108+
l_stop_block varchar2(100) := 'call dbms_plsql_code_coverage.stop_coverage()';
108109
begin
109110
if not g_develop_mode then
110111
g_is_started := false;
111112
if get_coverage_type = 'block' then
112-
dbms_plsql_code_coverage.stop_coverage;
113+
execute immediate l_stop_block;
113114
else
114115
dbms_profiler.stop_profiler();
115116
end if;

0 commit comments

Comments
 (0)