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

Skip to content

Commit b02f997

Browse files
committed
Implemented reporting to dbms_application_info
1 parent 6a527c6 commit b02f997

5 files changed

Lines changed: 74 additions & 0 deletions

File tree

source/core/types/ut_test.tpb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ create or replace type body ut_test as
5454

5555
a_listener.fire_before_event(ut_utils.gc_test,self);
5656
self.start_time := current_timestamp;
57+
58+
-- report to application_info
59+
ut_utils.set_action(self.object_owner||'.'||self.object_name||'.'||self.name);
5760

5861
if self.get_disabled_flag() then
5962
self.result := ut_utils.tr_disabled;

source/core/ut_utils.pkb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ create or replace package body ut_utils is
340340
end if;
341341
return l_result;
342342
end;
343+
344+
procedure set_action(a_test_name in varchar2) is
345+
begin
346+
dbms_application_info.set_module('utPLSQL', a_test_name);
347+
end;
343348

344349
function to_xpath(a_list varchar2, a_ancestors varchar2 := '/*/') return varchar2 is
345350
l_xpath varchar2(32767) := a_list;

source/core/ut_utils.pks

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ create or replace package ut_utils authid definer is
218218
procedure append_to_clob(a_src_clob in out nocopy clob, a_new_data varchar2);
219219

220220
function convert_collection(a_collection ut_varchar2_list) return ut_varchar2_rows;
221+
222+
/**
223+
* Set session's action and module using dbms_application_info
224+
*/
225+
procedure set_action(a_test_name in varchar2);
221226

222227
function to_xpath(a_list varchar2, a_ancestors varchar2 := '/*/') return varchar2;
223228

tests/RunAll.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ exec ut_coverage.coverage_start_develop();
233233
@@lib/RunTest.sql ut_test/ut_test.TestOutputGathering.sql
234234
@@lib/RunTest.sql ut_test/ut_test.TestOutputGatheringWhenEmpty.sql
235235
@@lib/RunTest.sql ut_test/ut_test.ReportWarningOnRollbackFailed.sql
236+
@@lib/RunTest.sql ut_test/ut_test.ApplicationInfoOnExecution.sql
236237

237238
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsATestWhenAfterTestFails.sql
238239
@@lib/RunTest.sql ut_test_suite/ut_test_suite.ErrorsATestWhenBeforeTestFails.sql
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
create or replace package ut_output_tests
2+
as
3+
--%suite
4+
5+
--%test
6+
procedure ut_passing_test;
7+
8+
end;
9+
/
10+
11+
create or replace package body ut_output_tests
12+
as
13+
14+
procedure ut_passing_test
15+
as
16+
l_module_name varchar2(4000);
17+
l_action_name varchar2(4000);
18+
begin
19+
--Generate empty output
20+
dbms_output.put_line('');
21+
ut.expect(1,'Test 1 Should Pass').to_equal(1);
22+
dbms_application_info.read_module(module_name => l_module_name, action_name => l_action_name);
23+
ut.expect(l_module_name).to_equal('utPLSQL');
24+
ut.expect(l_action_name).to_be_like('%.ut_output_tests.ut_passing_test');
25+
end;
26+
27+
end;
28+
/
29+
30+
declare
31+
l_output_data dbms_output.chararr;
32+
l_num_lines integer := 100000;
33+
l_output clob;
34+
begin
35+
--act
36+
ut.run('ut_output_tests');
37+
38+
--assert
39+
dbms_output.get_lines( l_output_data, l_num_lines);
40+
dbms_lob.createtemporary(l_output,true);
41+
for i in 1 .. l_num_lines loop
42+
dbms_lob.append(l_output,l_output_data(i));
43+
end loop;
44+
45+
if l_output like '%0 failed, 0 errored, 0 disabled, 0 warning(s)%' then
46+
:test_result := ut_utils.tr_success;
47+
end if;
48+
49+
if :test_result != ut_utils.tr_success or :test_result is null then
50+
for i in 1 .. l_num_lines loop
51+
dbms_output.put_line(l_output_data(i));
52+
end loop;
53+
dbms_output.put_line('Failed: Wrong output');
54+
end if;
55+
end;
56+
/
57+
58+
drop package ut_output_tests
59+
/
60+

0 commit comments

Comments
 (0)