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

Skip to content

Commit 858372c

Browse files
committed
Adding set of tests:
reporters/test_coverage reporters/test_debug_reporter reporters/test_documentation_reporter reporters/test_extended_coverage reporters/test_realtime_reporter Fixing some helper methods.
1 parent a6a848d commit 858372c

21 files changed

Lines changed: 1048 additions & 5 deletions

test/grant_ut3_owner_to_ut3_tester.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ begin
1717
and generated = 'N'
1818
and lower(object_name) not like 'sys%')
1919
loop
20-
execute immediate 'grant execute on ut3.'||i.object_name||' to UT3_TESTER';
20+
execute immediate 'grant execute on ut3."'||i.object_name||'" to UT3_TESTER';
2121
end loop;
2222
end;
2323
/

test/install_ut3_tester_helper.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ alter session set plsql_optimize_level=0;
1111
@@ut3_tester_helper/test_tab_varray.tps
1212
@@ut3_tester_helper/test_dummy_number.tps
1313
@@ut3_tester_helper/ut_test_table.sql
14+
@@ut3_tester_helper/test_event_object.tps
15+
@@ut3_tester_helper/test_event_list.tps
1416

1517
@@ut3_tester_helper/main_helper.pks
1618
@@ut3_tester_helper/run_helper.pks
19+
@@ut3_tester_helper/coverage_helper.pks
1720
@@ut3_tester_helper/expectations_helper.pks
1821
@@ut3_tester_helper/ut_example_tests.pks
1922

2023
@@ut3_tester_helper/main_helper.pkb
2124
@@ut3_tester_helper/run_helper.pkb
25+
@@ut3_tester_helper/coverage_helper.pkb
2226
@@ut3_tester_helper/expectations_helper.pkb
2327
@@ut3_tester_helper/ut_example_tests.pkb
2428

test/install_ut3_user_tests.sql

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ prompt Install user tests
2525
@@ut3_user/reporters/test_teamcity_reporter.pks
2626
@@ut3_user/reporters/test_sonar_test_reporter.pks
2727
@@ut3_user/reporters/test_junit_reporter.pks
28+
@@ut3_user/reporters/test_documentation_reporter.pks
29+
@@ut3_user/reporters/test_debug_reporter.pks
30+
@@ut3_user/reporters/test_realtime_reporter.pks
31+
@@ut3_user/reporters/test_coverage.pks
32+
set define on
33+
@@install_above_12_1.sql 'ut3_user/reporters/test_extended_coverage.pks'
34+
set define off
2835

29-
36+
--set define on
37+
--@@install_below_12_2.sql 'ut3_user/reporters/test_proftag_coverage.pks'
38+
--@@install_below_12_2.sql 'ut3_user/reporters/test_coverage/test_html_proftab_reporter.pks'
39+
--set define off
3040

3141
@@ut3_user/expectations/unary/test_expect_not_to_be_null.pkb
3242
@@ut3_user/expectations/unary/test_expect_to_be_null.pkb
@@ -48,6 +58,18 @@ prompt Install user tests
4858
@@ut3_user/reporters/test_teamcity_reporter.pkb
4959
@@ut3_user/reporters/test_sonar_test_reporter.pkb
5060
@@ut3_user/reporters/test_junit_reporter.pkb
61+
@@ut3_user/reporters/test_documentation_reporter.pkb
62+
@@ut3_user/reporters/test_debug_reporter.pkb
63+
@@ut3_user/reporters/test_realtime_reporter.pkb
64+
@@ut3_user/reporters/test_coverage.pkb
65+
set define on
66+
@@install_above_12_1.sql 'ut3_user/reporters/test_extended_coverage.pkb'
67+
set define off
68+
69+
--set define on
70+
--@@install_below_12_2.sql 'ut3_user/reporters/test_coverage.pkb'
71+
--@@install_below_12_2.sql 'ut3_user/reporters/test_coverage/test_html_proftab_reporter.pkb'
72+
--set define off
5173

5274

5375
set linesize 200
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
create or replace package body coverage_helper is
2+
3+
function get_mock_run_id return integer is
4+
v_result integer;
5+
begin
6+
select nvl(min(runid),0) - 1 into v_result
7+
from ut3.plsql_profiler_runs;
8+
return v_result;
9+
end;
10+
11+
function get_mock_block_run_id return integer is
12+
v_result integer;
13+
begin
14+
select nvl(min(run_id),0) - 1 into v_result
15+
from dbmspcc_runs;
16+
return v_result;
17+
end;
18+
19+
procedure mock_coverage_data(a_run_id integer,a_user in varchar2) is
20+
c_unit_id constant integer := 1;
21+
begin
22+
insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment)
23+
values(a_run_id, a_user, sysdate, 'unit testing utPLSQL');
24+
25+
insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name)
26+
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE');
27+
28+
insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time)
29+
select a_run_id, c_unit_id, 4, 1, 1 from dual union all
30+
select a_run_id, c_unit_id, 5, 0, 0 from dual union all
31+
select a_run_id, c_unit_id, 7, 1, 1 from dual;
32+
end;
33+
34+
procedure cleanup_dummy_coverage(a_run_id in integer) is
35+
pragma autonomous_transaction;
36+
begin
37+
delete from ut3.plsql_profiler_data where runid = a_run_id;
38+
delete from ut3.plsql_profiler_units where runid = a_run_id;
39+
delete from ut3.plsql_profiler_runs where runid = a_run_id;
40+
commit;
41+
end;
42+
43+
procedure create_dummy_coverage_package is
44+
pragma autonomous_transaction;
45+
begin
46+
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE is
47+
procedure do_stuff;
48+
49+
procedure grant_myself;
50+
end;]';
51+
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE is
52+
procedure do_stuff is
53+
begin
54+
if 1 = 2 then
55+
dbms_output.put_line('should not get here');
56+
else
57+
dbms_output.put_line('should get here');
58+
end if;
59+
end;
60+
61+
procedure grant_myself is
62+
begin
63+
execute immediate 'grant debug,execute on UT3.DUMMY_COVERAGE to ut3$user#';
64+
end;
65+
end;]';
66+
67+
end;
68+
69+
procedure create_dummy_coverage_test is
70+
pragma autonomous_transaction;
71+
begin
72+
execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE is
73+
--%suite(dummy coverage test)
74+
--%suitepath(coverage_testing)
75+
76+
--%test
77+
procedure test_do_stuff;
78+
79+
procedure grant_myself;
80+
end;]';
81+
execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE is
82+
procedure test_do_stuff is
83+
begin
84+
dummy_coverage.do_stuff;
85+
end;
86+
87+
procedure grant_myself is
88+
begin
89+
execute immediate 'grant debug,execute on UT3.TEST_DUMMY_COVERAGE to ut3$user#';
90+
end;
91+
end;]';
92+
93+
end;
94+
95+
procedure grant_exec_on_cov is
96+
pragma autonomous_transaction;
97+
begin
98+
execute immediate 'begin UT3.DUMMY_COVERAGE.grant_myself(); end;';
99+
execute immediate 'begin UT3.TEST_DUMMY_COVERAGE.grant_myself(); end;';
100+
end;
101+
102+
procedure drop_dummy_coverage_pkg is
103+
pragma autonomous_transaction;
104+
begin
105+
begin execute immediate q'[drop package ut3.test_dummy_coverage]'; exception when others then null; end;
106+
begin execute immediate q'[drop package ut3.dummy_coverage]'; exception when others then null; end;
107+
end;
108+
109+
110+
--12.2 Setup
111+
procedure create_dummy_12_2_cov_pck is
112+
pragma autonomous_transaction;
113+
begin
114+
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG is
115+
procedure do_stuff(i_input in number);
116+
117+
procedure grant_myself;
118+
end;]';
119+
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG is
120+
procedure do_stuff(i_input in number) is
121+
begin
122+
if i_input = 2 then
123+
dbms_output.put_line('should not get here');
124+
else
125+
dbms_output.put_line('should get here');
126+
end if;
127+
end;
128+
129+
procedure grant_myself is
130+
begin
131+
execute immediate 'grant debug,execute on UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG to ut3$user#';
132+
end;
133+
134+
end;]';
135+
end;
136+
137+
procedure create_dummy_12_2_cov_test is
138+
pragma autonomous_transaction;
139+
begin
140+
execute immediate q'[create or replace package UT3.TEST_BLOCK_DUMMY_COVERAGE is
141+
--%suite(dummy coverage test)
142+
--%suitepath(coverage_testing)
143+
144+
--%test
145+
procedure test_do_stuff;
146+
147+
procedure grant_myself;
148+
149+
end;]';
150+
execute immediate q'[create or replace package body UT3.TEST_BLOCK_DUMMY_COVERAGE is
151+
procedure test_do_stuff is
152+
begin
153+
dummy_coverage_package_with_an_amazingly_long_name_that_you_would_not_think_of_in_real_life_project_because_its_simply_too_long.do_stuff(1);
154+
ut.expect(1).to_equal(1);
155+
end;
156+
157+
procedure grant_myself is
158+
begin
159+
execute immediate 'grant debug,execute on UT3.TEST_BLOCK_DUMMY_COVERAGE to ut3$user#';
160+
end;
161+
end;]';
162+
end;
163+
164+
procedure mock_block_coverage_data(a_run_id integer,a_user in varchar2) is
165+
c_unit_id constant integer := 1;
166+
begin
167+
insert into dbmspcc_runs ( run_id, run_owner, run_timestamp, run_comment)
168+
values(a_run_id, a_user, sysdate, 'unit testing utPLSQL');
169+
170+
insert into dbmspcc_units ( run_id, object_id, type, owner, name,last_ddl_time)
171+
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG',sysdate);
172+
173+
insert into dbmspcc_blocks ( run_id, object_id, line,block,col,covered,not_feasible)
174+
select a_run_id, c_unit_id,4,1,1,1,0 from dual union all
175+
select a_run_id, c_unit_id,4,2,2,0,0 from dual union all
176+
select a_run_id, c_unit_id,5,3,0,1,0 from dual union all
177+
select a_run_id, c_unit_id,7,4,1,1,0 from dual;
178+
end;
179+
180+
procedure mock_profiler_coverage_data(a_run_id integer,a_user in varchar2) is
181+
c_unit_id constant integer := 1;
182+
begin
183+
insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment)
184+
values(a_run_id, a_user, sysdate, 'unit testing utPLSQL');
185+
186+
insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name)
187+
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG');
188+
189+
insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time)
190+
select a_run_id, c_unit_id, 4, 1, 1 from dual union all
191+
select a_run_id, c_unit_id, 5, 0, 0 from dual union all
192+
select a_run_id, c_unit_id, 6, 1, 0 from dual union all
193+
select a_run_id, c_unit_id, 7, 1, 1 from dual;
194+
end;
195+
196+
procedure cleanup_dummy_coverage(a_block_id in integer, a_prof_id in integer) is
197+
pragma autonomous_transaction;
198+
begin
199+
begin execute immediate q'[drop package ut3.test_block_dummy_coverage]'; exception when others then null; end;
200+
begin execute immediate q'[drop package ut3.dummy_coverage_package_with_an_amazingly_long_name_that_you_would_not_think_of_in_real_life_project_because_its_simply_too_long]'; exception when others then null; end;
201+
delete from dbmspcc_blocks where run_id = a_block_id;
202+
delete from dbmspcc_units where run_id = a_block_id;
203+
delete from dbmspcc_runs where run_id = a_block_id;
204+
cleanup_dummy_coverage(a_prof_id);
205+
commit;
206+
end;
207+
208+
procedure grant_exec_on_12_2_cov is
209+
pragma autonomous_transaction;
210+
begin
211+
execute immediate 'begin UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG.grant_myself(); end;';
212+
execute immediate 'begin UT3.TEST_BLOCK_DUMMY_COVERAGE.grant_myself(); end;';
213+
end;
214+
end;
215+
/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
create or replace package coverage_helper is
2+
3+
g_run_id integer;
4+
5+
type prof_runs_tab is table of ut3.plsql_profiler_runs%rowtype;
6+
7+
function get_mock_run_id return integer;
8+
function get_mock_block_run_id return integer;
9+
procedure cleanup_dummy_coverage(a_run_id in integer);
10+
procedure mock_coverage_data(a_run_id integer,a_user in varchar2);
11+
12+
--Profiler coveage
13+
procedure create_dummy_coverage_package;
14+
procedure create_dummy_coverage_test;
15+
procedure grant_exec_on_cov;
16+
procedure mock_profiler_coverage_data(a_run_id integer,a_user in varchar2);
17+
procedure drop_dummy_coverage_pkg;
18+
19+
--Block coverage
20+
procedure create_dummy_12_2_cov_pck;
21+
procedure create_dummy_12_2_cov_test;
22+
procedure mock_block_coverage_data(a_run_id integer,a_user in varchar2);
23+
procedure cleanup_dummy_coverage(a_block_id in integer, a_prof_id in integer);
24+
procedure grant_exec_on_12_2_cov;
25+
26+
end;
27+
/

test/ut3_tester_helper/main_helper.pkb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,25 @@ create or replace package body main_helper is
134134
where srj.job_name = a_job_name;
135135
end;
136136

137+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_list, a_item varchar2) is
138+
begin
139+
ut3.ut_utils.append_to_list(a_list,a_item);
140+
end;
141+
142+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_rows, a_item varchar2) is
143+
begin
144+
ut3.ut_utils.append_to_list(a_list,a_item);
145+
end;
146+
147+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_rows, a_item clob) is
148+
begin
149+
ut3.ut_utils.append_to_list(a_list,a_item);
150+
end;
151+
152+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_rows, a_items ut3.ut_varchar2_rows) is
153+
begin
154+
ut3.ut_utils.append_to_list(a_list,a_items);
155+
end;
156+
137157
end;
138158
/

test/ut3_tester_helper/main_helper.pks

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ create or replace package main_helper is
3636
procedure parse_dummy_test_as_ut3$user#;
3737

3838
function get_job_count(a_job_name varchar2) return number;
39-
39+
40+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_list, a_item varchar2);
41+
42+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_rows, a_item varchar2);
43+
44+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_rows, a_item clob);
45+
46+
procedure append_to_list(a_list in out nocopy ut3.ut_varchar2_rows, a_items ut3.ut_varchar2_rows);
47+
4048
end;
4149
/

test/ut3_tester_helper/run_helper.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,6 @@ create or replace package body run_helper is
522522
begin
523523
delete from ut3.ut_output_buffer_tmp;
524524
end;
525-
525+
526526
end;
527527
/

test/ut3_tester_helper/run_helper.pks

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
create or replace package run_helper is
22

3+
g_run_id integer;
4+
35
type t_out_buff_tab is table of ut3.ut_output_buffer_tmp%rowtype;
6+
type prof_runs_tab is table of ut3.plsql_profiler_runs%rowtype;
47

58
procedure setup_cache_objects;
69
procedure setup_cache;
@@ -49,6 +52,6 @@ create or replace package run_helper is
4952

5053
function ut_output_buffer_tmp return t_out_buff_tab pipelined;
5154
procedure delete_buffer;
52-
55+
5356
end;
5457
/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
create or replace type test_event_list as table of test_event_object;
2+
/

0 commit comments

Comments
 (0)