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

Skip to content

Commit c5b606c

Browse files
committed
Updated tests. Added additional tests.
Changes ut_utils.table_to_clob to add newline after for each element from the table so that there is a symetry between functions: clob_to_table and table_to_clob
1 parent c589574 commit c5b606c

11 files changed

Lines changed: 248 additions & 196 deletions

source/core/ut_utils.pkb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,16 @@ create or replace package body ut_utils is
254254
return l_results;
255255
end;
256256

257-
function table_to_clob(a_text_table ut_varchar2_list) return clob is
257+
function table_to_clob(a_text_table ut_varchar2_list, a_delimiter varchar2:= chr(10)) return clob is
258258
l_result clob;
259259
l_text_table_rows integer := coalesce(cardinality(a_text_table),0);
260260
begin
261261
for i in 1 .. l_text_table_rows loop
262-
append_to_clob(l_result, a_text_table(i));
262+
if i < l_text_table_rows then
263+
append_to_clob(l_result, a_text_table(i)||a_delimiter);
264+
else
265+
append_to_clob(l_result, a_text_table(i));
266+
end if;
263267
end loop;
264268
return l_result;
265269
end;

source/core/ut_utils.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ create or replace package ut_utils authid definer is
185185
*/
186186
function clob_to_table(a_clob clob, a_max_amount integer := 32767, a_delimiter varchar2:= chr(10)) return ut_varchar2_list;
187187

188-
function table_to_clob(a_text_table ut_varchar2_list) return clob;
188+
function table_to_clob(a_text_table ut_varchar2_list, a_delimiter varchar2:= chr(10)) return clob;
189189

190190
/*
191191
Returns time difference in seconds (with miliseconds) between given timestamps

tests/RunAll.sql

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ create table ut$test_table (val varchar2(1));
2323
@@helpers/test_package_1.pck
2424
@@helpers/test_package_2.pck
2525
@@helpers/utplsql_test_reporter.typ
26+
@@helpers/test_reporters.pks
27+
@@helpers/test_reporters.pkb
2628

2729
--Start coverage in develop mode (coverage for utPLSQL framework)
2830
--Regular coverage excludes the framework
@@ -106,6 +108,7 @@ exec ut_coverage.coverage_start_develop();
106108
@@lib/RunTest.sql ut_output_buffer/send_line.DoesNotSendLineIfNullTextGiven.sql
107109
@@lib/RunTest.sql ut_output_buffer/send_line.SendsALineIntoBufferTable.sql
108110

111+
@@lib/RunTest.sql ut_reporters/ut_sonar_test_reporter.AcceptsFileMapping.sql
109112
@@lib/RunTest.sql ut_reporters/ut_sonar_test_reporter.ProducesExpectedOutputs.sql
110113
@@lib/RunTest.sql ut_reporters/ut_teamcity_reporter.ProducesExpectedOutputs.sql
111114

@@ -189,6 +192,7 @@ exec ut_coverage.coverage_start_develop();
189192
@@lib/RunTest.sql ut_test_suite/ut_test_suite.Rollback_type.ManualOnFailure.sql
190193

191194
@@ut_utils/ut_utils.clob_to_table.sql
195+
@@ut_utils/ut_utils.table_to_clob.sql
192196
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithInvalidValues.sql
193197
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithNullValue.sql
194198
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.Success.sql
@@ -227,6 +231,7 @@ drop package test_package_1;
227231
drop package test_package_2;
228232
drop package test_package_3;
229233
drop type utplsql_test_reporter;
234+
drop package test_reporters;
230235

231236
set timing on
232237
prompt Generating coverage data to reporter outputs
@@ -451,9 +456,9 @@ begin
451456
ut_coverage.coverage_stop_develop();
452457

453458
--run for the second time to get the coverage report
454-
-- l_reporter := ut_coverage_html_reporter( a_project_name => 'utPLSQL v3', a_file_paths => l_file_list );
455-
-- :html_reporter_id := l_reporter.reporter_id;
456-
-- l_reporter.after_calling_run(ut_run(ut_suite_items()));
459+
l_reporter := ut_coverage_html_reporter( a_project_name => 'utPLSQL v3', a_file_paths => l_file_list );
460+
:html_reporter_id := l_reporter.reporter_id;
461+
l_reporter.after_calling_run(ut_run(ut_suite_items()));
457462

458463
l_reporter := ut_coverage_sonar_reporter( a_file_paths => l_file_list );
459464
:sonar_reporter_id := l_reporter.reporter_id;
@@ -481,12 +486,12 @@ spool coverage.json
481486
select * from table(ut_output_buffer.get_lines(:coveralls_reporter_id));
482487
spool off
483488

484-
-- set termout on
485-
-- prompt Spooling outcomes to coverage.html
486-
-- set termout off
487-
-- spool coverage.html
488-
-- exec ut_output_buffer.lines_to_dbms_output(:html_reporter_id);
489-
-- spool off
489+
set termout on
490+
prompt Spooling outcomes to coverage.html
491+
set termout off
492+
spool coverage.html
493+
exec ut_output_buffer.lines_to_dbms_output(:html_reporter_id);
494+
spool off
490495

491496
@@lib/mystats/mystats stop t=1000
492497

tests/helpers/test_reporters.pkb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
create or replace package body test_reporters
2+
as
3+
4+
procedure beforetest is
5+
begin
6+
dbms_output.put_line('<!beforetest!>');
7+
end;
8+
9+
procedure aftertest
10+
is
11+
begin
12+
dbms_output.put_line('<!aftertest!>');
13+
end;
14+
15+
procedure beforeeach is
16+
begin
17+
dbms_output.put_line('<!beforeeach!>');
18+
end;
19+
20+
procedure aftereach is
21+
begin
22+
dbms_output.put_line('<!aftereach!>');
23+
end;
24+
25+
procedure passing_test
26+
is
27+
begin
28+
dbms_output.put_line('<!passing test!>');
29+
ut.expect(1,'Test 1 Should Pass').to_equal(1);
30+
end;
31+
32+
procedure failing_test
33+
is
34+
begin
35+
dbms_output.put_line('<!failing test!>');
36+
ut.expect(1,'Fails as values are different').to_equal(2);
37+
end;
38+
39+
procedure erroring_test
40+
is
41+
l_variable integer;
42+
begin
43+
dbms_output.put_line('<!erroring test!>');
44+
l_variable := 'a string';
45+
ut.expect(l_variable).to_equal(1);
46+
end;
47+
48+
procedure disabled_test
49+
is
50+
begin
51+
dbms_output.put_line('<!this should not execute!>');
52+
ut.expect(1,'this should not execute').to_equal(1);
53+
end;
54+
55+
procedure beforeall is
56+
begin
57+
dbms_output.put_line('<!beforeall!>');
58+
end;
59+
60+
procedure afterall is
61+
begin
62+
dbms_output.put_line('<!afterall!>');
63+
end;
64+
65+
end;
66+
/
67+

tests/helpers/test_reporters.pks

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
create or replace package test_reporters
2+
as
3+
--%suite(A suite for testing different outcomes from reporters)
4+
5+
--%beforeall
6+
procedure beforeall;
7+
8+
--%beforeeach
9+
procedure beforeeach;
10+
11+
--%test
12+
--%beforetest(beforetest)
13+
--%aftertest(aftertest)
14+
procedure passing_test;
15+
16+
procedure beforetest;
17+
18+
procedure aftertest;
19+
20+
--%test(a test with failing assertion)
21+
procedure failing_test;
22+
23+
--%test(a test raising unhandled exception)
24+
procedure erroring_test;
25+
26+
--%test(a disabled test)
27+
--%disabled
28+
procedure disabled_test;
29+
30+
--%aftereach
31+
procedure aftereach;
32+
33+
--%afterall
34+
procedure afterall;
35+
36+
end;
37+
/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
declare
2+
l_output_data ut_varchar2_list;
3+
l_output varchar2(32767);
4+
l_expected varchar2(32767);
5+
begin
6+
l_expected := q'[<testExecutions version="1">
7+
<file path="tests/helpers/test_reporters.pkb">
8+
<testCase name="passing_test" duration="%" >%</testCase>
9+
<testCase name="failing_test" duration="%" >%<failure message="some expectations have failed">%</failure>%</testCase>
10+
<testCase name="erroring_test" duration="%" >%<error message="encountered errors">%</error>%</testCase>
11+
<testCase name="disabled_test" duration="0" >%<skipped message="skipped"/>%</testCase>
12+
</file>
13+
</testExecutions>]';
14+
15+
--act
16+
select *
17+
bulk collect into l_output_data
18+
from table(
19+
ut.run(
20+
'test_reporters',
21+
ut_sonar_test_reporter(
22+
ut_coverage.build_file_mappings( user, ut_varchar2_list('tests/helpers/test_reporters.pkb'))
23+
)
24+
)
25+
);
26+
27+
l_output := ut_utils.table_to_clob(l_output_data);
28+
29+
--assert
30+
if l_output like l_expected then
31+
:test_result := ut_utils.tr_success;
32+
else
33+
dbms_output.put_line('Actual:"'||l_output||'"');
34+
end if;
35+
end;
36+
/
Lines changed: 14 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,29 @@
1-
create or replace package ut_output_tests
2-
as
3-
--%suite
4-
5-
--%beforeeach
6-
procedure beforeeach;
7-
8-
--%aftereach
9-
procedure aftereach;
10-
11-
--%test
12-
--%beforetest(beforetest)
13-
--%aftertest(aftertest)
14-
procedure ut_passing_test;
15-
16-
procedure beforetest;
17-
18-
procedure aftertest;
19-
20-
--%beforeall
21-
procedure beforeall;
22-
--%afterall
23-
procedure afterall;
24-
25-
end;
26-
/
27-
28-
create or replace package body ut_output_tests
29-
as
30-
31-
procedure beforetest is
32-
begin
33-
dbms_output.put_line('<!beforetest!>');
34-
end;
35-
36-
procedure aftertest
37-
is
38-
begin
39-
dbms_output.put_line('<!aftertest!>');
40-
end;
41-
42-
procedure beforeeach is
43-
begin
44-
dbms_output.put_line('<!beforeeach!>');
45-
end;
46-
47-
procedure aftereach is
48-
begin
49-
dbms_output.put_line('<!aftereach!>');
50-
end;
51-
52-
procedure ut_passing_test
53-
is
54-
begin
55-
dbms_output.put_line('<!thetest!>');
56-
ut.expect(1,'Test 1 Should Pass').to_equal(1);
57-
end;
58-
59-
procedure beforeall is
60-
begin
61-
dbms_output.put_line('<!beforeall!>');
62-
end;
63-
64-
procedure afterall is
65-
begin
66-
dbms_output.put_line('<!afterall!>');
67-
end;
68-
69-
end;
70-
/
71-
721
declare
732
l_output_data ut_varchar2_list;
74-
l_output clob;
3+
l_output varchar2(32767);
4+
l_expected varchar2(32767);
755
begin
6+
l_expected := q'[<testExecutions version="1">
7+
<file path="tests/helpers/test_reporters.pkb">
8+
<testCase name="passing_test" duration="%" >%</testCase>
9+
<testCase name="failing_test" duration="%" >%<failure message="some expectations have failed">%</failure>%</testCase>
10+
<testCase name="erroring_test" duration="%" >%<error message="encountered errors">%</error>%</testCase>
11+
<testCase name="disabled_test" duration="0" >%<skipped message="skipped"/>%</testCase>
12+
</file>
13+
</testExecutions>]';
14+
7615
--act
7716
select *
7817
bulk collect into l_output_data
79-
from table(ut.run('ut_output_tests',ut_sonar_test_reporter(a_file_paths=>ut_varchar2_list('tests/ut_reporter/ut_output_tests.pkb'))));
18+
from table(ut.run('test_reporters',ut_sonar_test_reporter(a_file_paths=>ut_varchar2_list('tests/helpers/test_reporters.pkb'))));
8019

8120
l_output := ut_utils.table_to_clob(l_output_data);
8221

8322
--assert
84-
if l_output like '<testExecutions version="1">' ||
85-
'<file path="tests/ut_reporter/ut_output_tests.pkb">' ||
86-
'<testCase name="ut_passing_test" duration="%" >' ||
87-
'</testCase></file></testExecutions>' then
23+
if l_output like l_expected then
8824
:test_result := ut_utils.tr_success;
8925
else
90-
dbms_output.put_line(l_output);
26+
dbms_output.put_line('Actual:"'||l_output||'"');
9127
end if;
9228
end;
9329
/
94-
95-
drop package ut_output_tests
96-
/
97-

0 commit comments

Comments
 (0)