Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
287590b
12.2 Stable :
lwasylow Mar 11, 2018
68768f8
12.2 Stable :
lwasylow Mar 13, 2018
76bf869
12.2 Stable :
lwasylow Mar 13, 2018
1f4f5f0
Tests 12.2 Coverage:
lwasylow Mar 14, 2018
90858eb
Added 12.2 coverage
lwasylow Mar 14, 2018
d77cf9a
Test 12.2 coverage
lwasylow Mar 14, 2018
4f83357
Added 12.2 Coverage
lwasylow Mar 14, 2018
ac40332
Added 12.2 Coverage
lwasylow Mar 14, 2018
5f74db9
Merge pull request #602 from lwasylow/12coveragestab2
lwasylow Mar 14, 2018
9d7f16c
Added conditional install of tests for 12.2 only - when block coverag…
jgebal Mar 15, 2018
20541b5
Refactoring coverage:
lwasylow Mar 18, 2018
ab7eb93
Coverage Refactoring:
lwasylow Mar 23, 2018
8dbb1a1
Merge pull request #614 from lwasylow/feature/12cblockcoverage
lwasylow Mar 25, 2018
e0b220d
Merge branch 'develop' into feature/12cblockcoverage
lwasylow Mar 25, 2018
2560f5b
Revert "Feature/12cblockcoverage"
lwasylow Mar 25, 2018
6fe32c5
Merge pull request #615 from utPLSQL/revert-614-feature/12cblockcoverage
lwasylow Mar 25, 2018
8235848
Refactor Coverage:
lwasylow Mar 25, 2018
78fdab5
Refactor Coverage:
lwasylow Mar 25, 2018
3a19341
Merge branch 'feature/12cblockcoverage' of github.com:lwasylow/utPLSQ…
lwasylow Mar 25, 2018
466e126
Update test local
lwasylow Mar 25, 2018
e968f76
Merge pull request #616 from lwasylow/feature/12cblockcoverage
lwasylow Mar 25, 2018
0f1d789
12.2 coverage
lwasylow Apr 3, 2018
faab0fe
Merge pull request #625 from lwasylow/feature/12cblockcoverage
lwasylow Apr 3, 2018
35e5e13
12.2 coverage
lwasylow Apr 3, 2018
1289e99
Merge branch 'feature/12cblockcoverage' of github.com:lwasylow/utPLSQ…
lwasylow Apr 3, 2018
d3ce10c
Merge pull request #626 from lwasylow/feature/12cblockcoverage
lwasylow Apr 3, 2018
c0ca9d3
Fixing error in package name
lwasylow Apr 3, 2018
f151a6e
Update test
lwasylow Apr 4, 2018
28f7653
Statement Coverage First Commit
lwasylow Apr 7, 2018
1f51049
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into fea…
lwasylow Apr 7, 2018
9c87b06
Merge branch 'develop' of github.com:utPLSQL/utPLSQL into feature/12c…
lwasylow Apr 7, 2018
d8b8e87
Updated coverage with statement level information
lwasylow Apr 7, 2018
49b1b84
Move get_cov_sql function into common package to remove code duplication
lwasylow Apr 8, 2018
ab7eb24
Refactor Coverage to now enrich profile for partially covered lines u…
lwasylow Apr 8, 2018
36279fa
Update tests and fixed typo in original coverage reporter
lwasylow Apr 10, 2018
661ef74
Merge branch 'feature/12cblockcoverage' of https://github.com/utPLSQL…
lwasylow Apr 10, 2018
57f7a4f
Updated coverage
lwasylow Apr 11, 2018
3a2ff00
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into fea…
lwasylow Apr 11, 2018
e6c2be2
Merge pull request #640 from lwasylow/feature/12cov_extended
lwasylow Apr 11, 2018
c9cb004
Fixes to conditional compilation
lwasylow Apr 11, 2018
a862b95
Fixes to new asso array during mock coverage id.
lwasylow Apr 11, 2018
57ee184
Merge pull request #641 from lwasylow/feature/12cblockcoverage
lwasylow Apr 11, 2018
4561795
Update test
lwasylow Apr 11, 2018
0556fbe
Update test
lwasylow Apr 11, 2018
b91e51d
Merge branch 'feature/12cblockcoverage' of github.com:utPLSQL/utPLSQL…
lwasylow Apr 11, 2018
d19f941
Update test/core/reporters/test_extended_coverage.pkb
lwasylow Apr 11, 2018
e2e1437
Updated html reporter to show a information about the partially cover…
lwasylow Apr 11, 2018
a112e36
Added support for block coverage in sonar and cobertura reporters.
jgebal Apr 14, 2018
f0e2653
Clean-up and removal of unnecessary reporters
lwasylow Apr 15, 2018
4458dff
Unify reporters
lwasylow Apr 15, 2018
2027421
Update test
lwasylow Apr 15, 2018
924eb9b
Update issue with part covered being zero.
lwasylow Apr 15, 2018
a111c6d
Update for test with timestamp
lwasylow Apr 15, 2018
2d6c7d3
Merge branch 'develop' into feature/12cblockcoverage
lwasylow Apr 16, 2018
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
Prev Previous commit
Next Next commit
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into fea…
…ture/12cov_extended
  • Loading branch information
lwasylow committed Apr 11, 2018
commit 3a2ff000ad28c889c8a54baac620ae9c6bb19634
18 changes: 9 additions & 9 deletions docs/userguide/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ In order to be able to gather coverage information, the user executing unit test
* `create any procedure` system privilege
* `execute` privilege on the code that is being tested (not only the unit tests) or `execute any procedure` system privilege

If you have `execute` privilege on the code that is being tested, but do not have `create any procedure` system privilege, then the code that is being tested will be reported as not covered (coverage = 0%).
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.
If the code that is being tested is complied as NATIVE, the code coverage will not be reported as well.

## Running unit tests with coverage
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.
All you need to do, is pass the constructor of the reporter to your `ut.run`
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.
All you need to do is pass the constructor of the reporter to your `ut.run`

Example:
```sql
Expand All @@ -37,10 +41,8 @@ begin
end;
/
```


Executes all unit tests in current schema, gather information about code coverage and output the html text into DBMS_OUTPUT.
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/)
Executes all unit tests in the current schema, gathers information about code coverage and outputs the HTML text into DBMS_OUTPUT.
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/)

The report provides summary information with a list of source code that was expected to be covered.

Expand All @@ -65,9 +67,7 @@ end;

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.

## Coverage reporting options
By default the database schema/schemes containing the tests that were executed during the run, are fully reported by coverage reporter.
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.
### Coverage reporting options

There are two distinct ways to gather code coverage:
- Coverage on database schema(s)
Expand Down
2 changes: 0 additions & 2 deletions source/core/types/ut_run.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ create or replace type body ut_run as
l_exclude_objects ut_object_names;
l_coverage_type varchar2(32);
begin
l_coverage_schema_names := coalesce(a_schema_names, get_run_schemes());
l_exclude_objects := coalesce(a_exclude_objects,ut_object_names());
l_coverage_type := coalesce(a_coverage_type,'proftab');

self.run_paths := a_run_paths;
Expand Down
3 changes: 3 additions & 0 deletions test/core/reporters/test_coverage.pks
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ create or replace package test_coverage is
procedure coverage_for_object;

--%test(Coverage is gathered for specified schema - default coverage type)
procedure coverage_for_object_no_owner;

--%test(Coverage is gathered for specified schema)
procedure coverage_for_schema;

--%test(Coverage is gathered for specified file - default coverage type)
Expand Down
191 changes: 191 additions & 0 deletions test/core/reporters/test_extended_coverage.pkb
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
create or replace package body test_extended_coverage is

g_run_id ut3.ut_coverage_helper.g_coverage_arr;

function get_mock_block_run_id return integer is
v_result integer;
begin
select nvl(min(run_id),0) - 1 into v_result
from ut3.dbmspcc_runs;
return v_result;
end;

function get_mock_proftab_run_id return integer is
v_result integer;
begin
select nvl(min(runid),0) - 1 into v_result
from ut3.plsql_profiler_runs;
return v_result;
end;

procedure create_dummy_coverage_package is
pragma autonomous_transaction;
begin
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE is
procedure do_stuff(i_input in number);
end;]';
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE is
procedure do_stuff(i_input in number) is
begin
if i_input = 2 then
dbms_output.put_line('should not get here');
else
dbms_output.put_line('should get here');
end if;
end;
end;]';
end;

procedure create_dummy_coverage_test is
pragma autonomous_transaction;
begin
execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE is
--%suite(dummy coverage test)
--%suitepath(coverage_testing)

--%test
procedure test_do_stuff;
end;]';
execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE is
procedure test_do_stuff is
begin
dummy_coverage.do_stuff(1);
ut.expect(1).to_equal(1);
end;
end;]';
end;

procedure mock_block_coverage_data(a_run_id integer) is
c_unit_id constant integer := 1;
begin
insert into ut3.dbmspcc_runs ( run_id, run_owner, run_timestamp, run_comment)
values(a_run_id, user, sysdate, 'unit testing utPLSQL');

insert into ut3.dbmspcc_units ( run_id, object_id, type, owner, name,last_ddl_time)
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE',sysdate);

insert into ut3.dbmspcc_blocks ( run_id, object_id, line,block,col,covered,not_feasible)
select a_run_id, c_unit_id,4,1,1,1,0 from dual union all
select a_run_id, c_unit_id,4,2,2,0,0 from dual union all
select a_run_id, c_unit_id,5,3,0 ,1,0 from dual union all
select a_run_id, c_unit_id,7,4,1,1,0 from dual;
end;

procedure mock_profiler_coverage_data(a_run_id integer) is
c_unit_id constant integer := 1;
begin
insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment)
values(a_run_id, user, sysdate, 'unit testing utPLSQL');

insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name)
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE');

insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time)
select a_run_id, c_unit_id, 4, 1, 1 from dual union all
select a_run_id, c_unit_id, 5, 0, 0 from dual union all
select a_run_id, c_unit_id, 6, 1, 0 from dual union all
select a_run_id, c_unit_id, 7, 1, 1 from dual;
end;

procedure setup_dummy_coverage is
pragma autonomous_transaction;
begin
create_dummy_coverage_package();
create_dummy_coverage_test();
g_run_id(ut3.ut_coverage.gc_block_coverage) := get_mock_block_run_id();
g_run_id(ut3.ut_coverage.gc_proftab_coverage) := get_mock_proftab_run_id();
ut3.ut_coverage_helper.mock_coverage_id(g_run_id);
mock_block_coverage_data(g_run_id(ut3.ut_coverage.gc_proftab_coverage));
mock_profiler_coverage_data(g_run_id(ut3.ut_coverage.gc_block_coverage));
commit;
end;

procedure cleanup_dummy_coverage is
pragma autonomous_transaction;
begin
begin execute immediate q'[drop package ut3.test_dummy_coverage]'; exception when others then null; end;
begin execute immediate q'[drop package ut3.dummy_coverage]'; exception when others then null; end;
delete from ut3.dbmspcc_blocks where run_id = g_run_id(ut3.ut_coverage.gc_block_coverage);
delete from ut3.dbmspcc_units where run_id = g_run_id(ut3.ut_coverage.gc_block_coverage);
delete from ut3.dbmspcc_runs where run_id = g_run_id(ut3.ut_coverage.gc_block_coverage);
delete from ut3.plsql_profiler_data where runid = g_run_id(ut3.ut_coverage.gc_proftab_coverage);
delete from ut3.plsql_profiler_units where runid = g_run_id(ut3.ut_coverage.gc_proftab_coverage);
delete from ut3.plsql_profiler_runs where runid = g_run_id(ut3.ut_coverage.gc_proftab_coverage);
commit;
end;

procedure coverage_for_object is
l_expected clob;
l_actual clob;
l_results ut3.ut_varchar2_list;
begin
--Arrange
l_expected := '%<file path="ut3.dummy_coverage">%';
--Act
select *
bulk collect into l_results
from table(
ut3.ut.run(
a_path => 'ut3.test_dummy_coverage',
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
a_coverage_type => 'extended',
a_include_objects => ut3.ut_varchar2_list( 'ut3.dummy_coverage' )
)
);
--Assert
l_actual := ut3.ut_utils.table_to_clob(l_results);
ut.expect(l_actual).to_be_like(l_expected);
end;

procedure coverage_for_schema is
l_expected clob;
l_actual clob;
l_results ut3.ut_varchar2_list;
begin
--Arrange
l_expected := '<file path="ut3.%">';
l_expected := '%'||l_expected||'%'||l_expected||'%';
--Act
select *
bulk collect into l_results
from table(
ut3.ut.run(
a_path => 'ut3.test_dummy_coverage',
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
a_coverage_type => 'extended',
a_coverage_schemes => ut3.ut_varchar2_list( 'ut3' )
)
);
--Assert
l_actual := ut3.ut_utils.table_to_clob(l_results);
ut.expect(l_actual).to_be_like(l_expected);
end;

procedure coverage_for_file is
l_expected clob;
l_actual clob;
l_results ut3.ut_varchar2_list;
l_file_path varchar2(100);
begin
--Arrange
l_file_path := lower('test/ut3.dummy_coverage.pkb');
l_expected := '%<file path="'||l_file_path||'">%';
--Act
select *
bulk collect into l_results
from table(
ut3.ut.run(
a_path => 'ut3.test_dummy_coverage',
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
a_coverage_type => 'extended',
a_source_files => ut3.ut_varchar2_list( l_file_path ),
a_test_files => ut3.ut_varchar2_list( )
)
);
--Assert
l_actual := ut3.ut_utils.table_to_clob(l_results);
ut.expect(l_actual).to_be_like(l_expected);
end;

end;
/
22 changes: 22 additions & 0 deletions test/core/reporters/test_extended_coverage.pks
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
create or replace package test_extended_coverage is

--%suite
--%suitepath(utplsql.core.reporters)

--%beforeall
procedure setup_dummy_coverage;

--%afterall
procedure cleanup_dummy_coverage;

--%test(Coverage is gathered for specified object - extended coverage type)
procedure coverage_for_object;

--%test(Coverage is gathered for specified schema - extended coverage type)
procedure coverage_for_schema;

--%test(Coverage is gathered for specified file - extended coverage type)
procedure coverage_for_file;

end;
/
You are viewing a condensed version of this merge commit. You can view the full changes here.