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

Skip to content

Commit b441c54

Browse files
committed
Test files are now reporter in flattened format.
Fixed a bug where sonar_test_reporter was reporting test files as nested due to suitepath nesting.
1 parent f9b8191 commit b441c54

7 files changed

Lines changed: 81 additions & 65 deletions

source/reporters/ut_sonar_test_reporter.tpb

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,75 @@ create or replace type body ut_sonar_test_reporter is
2424
return;
2525
end;
2626

27-
overriding member procedure before_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run) is
28-
begin
29-
self.file_mappings := coalesce(a_run.test_file_mappings,ut_file_mappings());
30-
self.print_text('<testExecutions version="1">');
31-
end;
27+
overriding member procedure after_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run) is
3228

33-
overriding member procedure before_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite) is
29+
function map_package_to_file(a_suite ut_suite, a_file_mappings ut_file_mappings) return varchar2 is
3430
l_file_name varchar2(4000);
35-
begin
36-
if a_suite is of (ut_suite) then
37-
for i in 1 .. self.file_mappings.count loop
38-
if upper(self.file_mappings(i).object_name) = upper(a_suite.object_name)
39-
and upper(self.file_mappings(i).object_owner) = upper(a_suite.object_owner) then
40-
l_file_name := self.file_mappings(i).file_name;
41-
exit;
31+
begin
32+
if a_file_mappings is not null then
33+
for i in 1 .. a_file_mappings.count loop
34+
if upper(a_file_mappings(i).object_name) = upper(a_suite.object_name)
35+
and upper(a_file_mappings(i).object_owner) = upper(a_suite.object_owner) then
36+
l_file_name := a_file_mappings(i).file_name;
37+
exit;
38+
end if;
39+
end loop;
40+
end if;
41+
return coalesce(l_file_name, a_suite.path);
42+
end;
43+
44+
procedure print_test_results(a_test ut_test) is
45+
l_lines ut_varchar2_list;
46+
begin
47+
self.print_text('<testCase name="'||a_test.name||'" duration="'||round(a_test.execution_time()*1000,0)||'" >');
48+
if a_test.result = ut_utils.tr_disabled then
49+
self.print_text('<skipped message="skipped"/>');
50+
elsif a_test.result = ut_utils.tr_error then
51+
self.print_text('<error message="encountered errors">');
52+
self.print_text('<![CDATA[');
53+
self.print_clob(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
54+
self.print_text(']]>');
55+
self.print_text('</error>');
56+
elsif a_test.result > ut_utils.tr_success then
57+
self.print_text('<failure message="some expectations have failed">');
58+
self.print_text('<![CDATA[');
59+
for i in 1 .. a_test.results.count loop
60+
l_lines := a_test.results(i).get_result_lines();
61+
for i in 1 .. l_lines.count loop
62+
self.print_text(l_lines(i));
63+
end loop;
64+
end loop;
65+
self.print_text(']]>');
66+
self.print_text('</failure>');
67+
end if;
68+
self.print_text('</testCase>');
69+
end;
70+
71+
procedure print_suite_results(a_suite ut_logical_suite, a_file_mappings ut_file_mappings) is
72+
begin
73+
for i in 1 .. a_suite.items.count loop
74+
if a_suite.items(i) is of(ut_logical_suite) then
75+
print_suite_results(treat(a_suite.items(i) as ut_logical_suite), a_file_mappings);
4276
end if;
4377
end loop;
44-
l_file_name := coalesce(l_file_name, a_suite.path);
45-
self.print_text('<file path="'||l_file_name||'">');
46-
end if;
47-
end;
78+
if a_suite is of(ut_suite) then
79+
self.print_text('<file path="'||map_package_to_file(treat(a_suite as ut_suite), a_file_mappings)||'">');
4880

49-
overriding member procedure after_calling_test(self in out nocopy ut_sonar_test_reporter, a_test ut_test) is
50-
l_message varchar2(32757);
51-
l_lines ut_varchar2_list;
52-
begin
53-
self.print_text('<testCase name="'||a_test.name||'" duration="'||round(a_test.execution_time()*1000,0)||'" >');
54-
if a_test.result = ut_utils.tr_disabled then
55-
self.print_text('<skipped message="skipped"/>');
56-
elsif a_test.result = ut_utils.tr_error then
57-
self.print_text('<error message="encountered errors">');
58-
self.print_text('<![CDATA[');
59-
self.print_clob(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
60-
self.print_text(']]>');
61-
self.print_text('</error>');
62-
elsif a_test.result > ut_utils.tr_success then
63-
self.print_text('<failure message="some expectations have failed">');
64-
self.print_text('<![CDATA[');
65-
for i in 1 .. a_test.results.count loop
66-
l_lines := a_test.results(i).get_result_lines();
67-
for i in 1 .. l_lines.count loop
68-
self.print_text(l_lines(i));
81+
for i in 1 .. a_suite.items.count loop
82+
if a_suite.items(i) is of(ut_test) then
83+
print_test_results(treat(a_suite.items(i) as ut_test));
84+
end if;
6985
end loop;
70-
end loop;
71-
self.print_text(']]>');
72-
self.print_text('</failure>');
73-
end if;
74-
self.print_text('</testCase>');
75-
end;
86+
self.print_text('</file>');
87+
end if;
88+
end;
7689

77-
overriding member procedure after_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite) is
7890
begin
79-
if a_suite is of (ut_suite) then
80-
self.print_text('</file>');
81-
end if;
82-
end;
91+
self.print_text('<testExecutions version="1">');
92+
for i in 1 .. a_run.items.count loop
93+
print_suite_results(treat(a_run.items(i) as ut_logical_suite), a_run.test_file_mappings);
94+
end loop;
8395

84-
overriding member procedure after_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run) is
85-
begin
8696
self.print_text('</testExecutions>');
8797
end;
8898

source/reporters/ut_sonar_test_reporter.tps

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ create or replace type ut_sonar_test_reporter under ut_reporter_base(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18-
file_mappings ut_file_mappings,
1918

2019
constructor function ut_sonar_test_reporter(
2120
self in out nocopy ut_sonar_test_reporter
2221
) return self as result,
2322

24-
overriding member procedure before_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run),
25-
overriding member procedure before_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite),
26-
overriding member procedure after_calling_test(self in out nocopy ut_sonar_test_reporter, a_test ut_test),
27-
overriding member procedure after_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite),
2823
overriding member procedure after_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run)
2924
)
3025
not final

tests/helpers/test_reporters_1.pks

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
create or replace package test_reporters_1
22
as
33
--%suite(A suite for testing html coverage options)
4-
4+
--%suitepath(org.utplsql.utplsql.test.test_reporters)
5+
56
--%test(a test calling package outside schema)
67
procedure diffrentowner_test;
78

tests/ut_reporters/ut_documentation_reporter.providesCorrectLineFromStacktrace.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ begin
1313
%ORA-06502%
1414
%ORA-06512%
1515
Finished %
16-
4 tests, 1 failed, 1 errored%]';
16+
5 tests, 1 failed, 1 errored%]';
1717

1818
--act
1919
select *

tests/ut_reporters/ut_sonar_test_reporter.AcceptsFileMapping.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ declare
44
l_expected varchar2(32767);
55
begin
66
l_expected := q'[<testExecutions version="1">
7+
<file path="tests/helpers/test_reporters_1.pkb">
8+
<testCase name="diffrentowner_test" duration="%" >%</testCase>
9+
</file>
710
<file path="tests/helpers/test_reporters.pkb">
811
<testCase name="passing_test" duration="%" >%</testCase>
912
<testCase name="failing_test" duration="%" >%<failure message="some expectations have failed">%</failure>%</testCase>
@@ -19,7 +22,7 @@ begin
1922
ut.run(
2023
'test_reporters',
2124
ut_sonar_test_reporter(),
22-
a_test_file_mappings => ut_file_mapper.build_file_mappings( user, ut_varchar2_list('tests/helpers/test_reporters.pkb'))
25+
a_test_file_mappings => ut_file_mapper.build_file_mappings( user, ut_varchar2_list('tests/helpers/test_reporters.pkb', 'tests/helpers/test_reporters_1.pkb'))
2326
)
2427
);
2528

tests/ut_reporters/ut_sonar_test_reporter.ProducesExpectedOutputs.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ declare
44
l_expected varchar2(32767);
55
begin
66
l_expected := q'[<testExecutions version="1">
7+
<file path="tests/helpers/test_reporters_1.pkb">
8+
<testCase name="diffrentowner_test" duration="%" >%</testCase>
9+
</file>
710
<file path="tests/helpers/test_reporters.pkb">
811
<testCase name="passing_test" duration="%" >%</testCase>
912
<testCase name="failing_test" duration="%" >%<failure message="some expectations have failed">%</failure>%</testCase>
@@ -15,7 +18,7 @@ begin
1518
--act
1619
select *
1720
bulk collect into l_output_data
18-
from table(ut.run('test_reporters',ut_sonar_test_reporter(),a_source_files=> null, a_test_files=>ut_varchar2_list('tests/helpers/test_reporters.pkb')));
21+
from table(ut.run('test_reporters',ut_sonar_test_reporter(),a_source_files=> null, a_test_files=>ut_varchar2_list('tests/helpers/test_reporters.pkb', 'tests/helpers/test_reporters_1.pkb')));
1922

2023
l_output := ut_utils.table_to_clob(l_output_data);
2124

tests/ut_reporters/ut_xunit_reporter.ProducesExpectedOutputs.sql

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ declare
33
l_output varchar2(32767);
44
l_expected varchar2(32767);
55
begin
6-
l_expected := q'[<testsuites tests="4" skipped="1" error="1" failure="1" name="%" time="%" >
7-
<testsuite tests="4" id="1" package="org" skipped="1" error="1" failure="1" name="org" time="%" >
8-
<testsuite tests="4" id="2" package="org.utplsql" skipped="1" error="1" failure="1" name="utplsql" time="%" >
9-
<testsuite tests="4" id="3" package="org.utplsql.utplsql" skipped="1" error="1" failure="1" name="utplsql" time="%" >
10-
<testsuite tests="4" id="4" package="org.utplsql.utplsql.test" skipped="1" error="1" failure="1" name="test" time="%" >
11-
<testsuite tests="4" id="5" package="org.utplsql.utplsql.test.test_reporters" skipped="1" error="1" failure="1" name="%" time="%" >
6+
l_expected := q'[<testsuites tests="5" skipped="1" error="1" failure="1" name="%" time="%" >
7+
<testsuite tests="5" id="1" package="org" skipped="1" error="1" failure="1" name="org" time="%" >
8+
<testsuite tests="5" id="2" package="org.utplsql" skipped="1" error="1" failure="1" name="utplsql" time="%" >
9+
<testsuite tests="5" id="3" package="org.utplsql.utplsql" skipped="1" error="1" failure="1" name="utplsql" time="%" >
10+
<testsuite tests="5" id="4" package="org.utplsql.utplsql.test" skipped="1" error="1" failure="1" name="test" time="%" >
11+
<testsuite tests="5" id="5" package="org.utplsql.utplsql.test.test_reporters" skipped="1" error="1" failure="1" name="%" time="%" >
1212
<system-out>%<!beforeall!>%<!afterall!>%</system-out>
1313
<testcase classname="org.utplsql.utplsql.test.test_reporters" assertions="1" skipped="0" error="0" failure="0" name="%" time="%" >
1414
<system-out>%<!beforeeach!>%<!beforetest!>%<!passing test!>%<!aftertest!>%<!aftereach!>%</system-out>
@@ -25,6 +25,10 @@ Actual: 1 (number) was expected to equal: 2 (number)%</failure>
2525
<testcase classname="org.utplsql.utplsql.test.test_reporters" assertions="0" skipped="1" error="0" failure="0" name="%" time="0" status="Disabled">
2626
<skipped/>
2727
</testcase>
28+
<testsuite tests="1" id="6" package="org.utplsql.utplsql.test.test_reporters.test_reporters_1" skipped="0" error="0" failure="0" name="%" time="%" >
29+
<testcase classname="org.utplsql.utplsql.test.test_reporters.test_reporters_1" assertions="1" skipped="0" error="0" failure="0" name="%" time="%" >
30+
</testcase>
31+
</testsuite>
2832
</testsuite>
2933
</testsuite>
3034
</testsuite>

0 commit comments

Comments
 (0)