You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
utPLSQL comes with a built-in coverage reporting engine. The code coverage reporting is based on the DBMS_PROFILER package provided with Oracle database.
4
+
utPLSQL comes with a built-in coverage reporting engine. The code coverage reporting uses DBMS_PROFILER package provided with Oracle database.
5
5
Code coverage is gathered for the following source types:
6
6
* package bodies
7
7
* type bodies
@@ -11,9 +11,9 @@ Code coverage is gathered for the following source types:
11
11
12
12
**Note**
13
13
14
-
> The package and type specifications are explicitly excluded from code coverage analysis. This limitation is introduced to avoid false-negatives. Typically package specifications contain no executable code. The only exception is initialization of global constants and variables in package specification. Since most package specifications are not executable at all, there is no information available on the number of lines covered and those would be reported as 0% covered, which is not desirable.
14
+
> The package and type specifications are excluded from code coverage analysis. This limitation is introduced to avoid false-negatives. Typically package specifications contain no executable code. The only exception is initialization of global constants and variables in package specification. Since most package specifications are not executable at all, there is no information available on the number of lines covered and those would be reported as 0% covered, which is not desirable.
15
15
16
-
To obtain information about code coverage of your unit tests, all you need to do is run your unit tests with one of built-in code coverage reporters.
16
+
To obtain information about code coverage for unit tests, run utPLSQL with one of built-in code coverage reporters.
17
17
The following code coverage reporters are supplied with utPLSQL:
18
18
*`ut_coverage_html_reporter` - generates a HTML coverage report providing summary and detailed information on code coverage. The HTML reporter is based on the open-source [simplecov-html](https://github.com/colszowka/simplecov-html) reporter for Ruby. It includes source code of the code that was covered (if possible)
19
19
*`ut_coveralls_reporter` - generates a [Coveralls compatible JSON](https://coveralls.zendesk.com/hc/en-us/articles/201774865-API-Introduction) coverage report providing detailed information on code coverage with line numbers. This coverage report is designed to be consumed by cloud services like [Coveralls](https://coveralls.io)
@@ -33,8 +33,8 @@ If you have `execute` privilege only on the unit tests, but do not have `execute
33
33
If the code that is being tested is complied as NATIVE, the code coverage will not be reported as well.
34
34
35
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 project. 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 your`ut.run`
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.
38
38
39
39
Example:
40
40
```sql
@@ -43,10 +43,10 @@ begin
43
43
end;
44
44
/
45
45
```
46
-
Executes all unit tests in the current schema, gathers information about code coverage and outputs the HTML text into DBMS_OUTPUT.
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
47
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/)
48
48
49
-
The report provides summary information with a list of source code that was expected to be covered.
49
+
The report provides summary information with a list of source code that should be covered.
@@ -57,8 +57,8 @@ The report allow you to navigate to each source file and inspect line by line co
57
57
58
58
#### Oracle 12.2 extended coverage with profiler and block coverage
59
59
Using data collected from profiler and block coverage running parallel we are able to enrich information about coverage.
60
-
For every line recorded by profiler if we have a partially covered same line in block coverage we will display that information
61
-
presenting line as partially covered, displaying number of block and how many blocks been covered in that line.The feature will be automatically enabled in the Oracle database version 12.2 and higher, for older versions current profiler will be used.
60
+
For every line recorded by the profiler if we have a partially covered same line in block coverage we will display that information
61
+
presenting line as partially covered, displaying number of block and how many blocks have been covered in that line.The feature will be automatically enabled in the Oracle database version 12.2 and higher, for older versions current profiler will be used.
62
62
63
63
utPLSQL installation automatically creates tables needed by `dbms_plsql_code_coverage` on databases in versions above 12c Release 1.
64
64
Due to security model of `dbms_plsql_code_coverage` package, utPLSQL grants access to those tables and creates synonyms for those tables.
@@ -92,7 +92,8 @@ The default behavior of coverage reporting can be altered using invocation param
92
92
93
93
### Schema based Coverage
94
94
95
-
To simply gather coverage for all objects in your current schema execute tests with coverage reporting.
95
+
To gather coverage for all objects in the **current schema** execute tests with coverage report as argument.
96
+
This is the default reporting option and therefore additional coverage options don't need to be provided.
By default, coverage is gathered on the schema(s) derived from suite paths provided to execute tests.
112
-
This is correct as long as your test packages and tested code share the same schema.
113
+
This is a valid approach as long as your test packages and tested code share the same schema.
113
114
114
115
So when you run:
115
116
```sql
@@ -531,8 +532,8 @@ Unit test code is mapped to files in `test_results.xml`
531
532
532
533
In order to allow deterministic and accurate mapping of database source-code into project files, the project directory and file structure needs to meet certain criteria.
533
534
- Source code is kept separate from test code (separate directories)
534
-
- Each database (source-code) object is stored in individual file. Package/type specification is kept separate from it's body.
535
-
- File name (file path) contains name of database object
535
+
- Each database (source-code) object is stored in an individual file. Package/type specification is kept separate from its body.
536
+
- File name (file path) contains the name of database object
536
537
- Each file-path clearly identifies object type (by file extension)
537
538
- Each file contains representation of database object "as is". No extra commands (like `set echo off``ALTER SESSION SET PLSQL_CCFLAGS = 'debug:TRUE';`) or blank lines are present before `CREATE TYPE`,`CREATE TYPE` etc.
538
539
- When project is spanning across multiple database schemes, each file-path clearly and uniformly identifies object owner
@@ -659,3 +660,119 @@ begin
659
660
end;
660
661
```
661
662
663
+
## Reporting coverage outside of utPLSQL
664
+
665
+
utPSLQL allows fo standalone reporting code coverage across multiple database sessions. This functionality enables coverage reporting for external testing tools.
666
+
667
+
Following API calls enable the standalone coverage reporting.
668
+
669
+
-`ut_runner.coverage_start( coverage_run_id );` - initiates code coverage within a session
670
+
-`ut_runner.coverage_stop();` - stops gathering of code coverage within a session
671
+
-`.get_report( ... )` - coverage reporters function producing coverage report as pipelined data-set (to be used in SQL query)
672
+
-`.get_report_cursor( ... )` - coverage reporters function producing coverage report as ref-cursor
673
+
674
+
Example:
675
+
```sql
676
+
--SESSION 1
677
+
-- gather coverage on code using specific coverage_run_id value
Specification of parameters for `get_report` and `get_report_cursor`
736
+
```sql
737
+
function get_report(
738
+
a_coverage_options ut_coverage_options,
739
+
a_client_character_set varchar2 :=null
740
+
) return ut_varchar2_rows pipelined
741
+
```
742
+
743
+
```sql
744
+
function get_report_cursor(
745
+
a_coverage_options ut_coverage_options,
746
+
a_client_character_set varchar2 :=null
747
+
) return sys_refcursor
748
+
```
749
+
```sql
750
+
ut_coverage_options(
751
+
coverage_run_id raw,
752
+
schema_names ut_varchar2_rows :=null,
753
+
exclude_objects ut_varchar2_rows :=null,
754
+
include_objects ut_varchar2_rows :=null,
755
+
file_mappings ut_file_mappings :=null
756
+
);
757
+
```
758
+
759
+
The `a_client_character_set` is used to provide character set to the report. Coverage reports in XML and HTML format include this information to assure that HMTL/XML encoding tag is aligned with encoding of the report produced.
760
+
Use this parameter to provide encoding of your client application.
761
+
762
+
The `a_coverage_options` parameter is used to control the scope and formatting of data returned by report.
763
+
764
+
`ut_coverage_options` object accepts the following arguments
765
+
766
+
-`coverage_run_id` - identifier of coverage run to generate report for - data-type `RAW(32)`
767
+
-`schema_names` - optional - list of schema names to include in coverage report - data-type `UT_VARCHAR2_ROWS`
768
+
-`exclude_objects` - optional - list of object names to exclude from report - data-type `UT_VARCHAR2_ROWS`
769
+
-`include_objects` - optional - list of object names to gather coverage on - data-type `UT_VARCHAR2_ROWS`
770
+
-`file_mappings` - optional - list of schema names to gather coverage on - data-type `UT_FILE_MAPPINGS`
771
+
772
+
`coverage_run_id` parameter identifies a common coverage run. The valid value type for that parameter is RAW(32).
773
+
It is recommended to use `sys_guid()` to generate a common, unique identifier for a specific coverage run.
774
+
If the identifier is not unique, previous runs of coverage that used the same `coverage_run_id` will be aggregated to the resulting coverage report.
775
+
776
+
For details on the meaning of `schema_names`, `exclude_objects`, `include_objects`, `file_mappings` see sections above.
777
+
Note that data-types of include/exclude/schema lists are different when calling `ut.run` vs. calling `get_report/get_report_cursor`.
0 commit comments