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

Skip to content

Commit 7c6103e

Browse files
committed
Changes to ut_test_object - reporter is IN parameter only.
Added install/removal of example objects in example scripts Added printing of leading spaces in sqlplus for custom reporter example. Split example reporter type into two files. Minor tweaks and refactorings.
1 parent c75b352 commit 7c6103e

18 files changed

Lines changed: 149 additions & 132 deletions

examples/RunExampleComplexSuiteWithDBMSOutputReporter.sql renamed to examples/RunExampleComplexSuiteWithCustomDBMSOutputReporter.sql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
44
Clear Screen
5-
Set Serveroutput On Size Unlimited
5+
Set Serveroutput On Size Unlimited format truncated
6+
set echo off
7+
--install the example unit test packages
8+
@@ut_exampletest.pks
9+
@@ut_exampletest.pkb
10+
@@ut_exampletest2.pks
11+
@@ut_exampletest2.pkb
12+
@@ut_custom_reporter.tps
13+
@@ut_custom_reporter.tpb
614

715
declare
816
suite1 ut_test_suite;
917
suite2 ut_test_suite;
1018
suite_complex ut_test_suite;
1119
testtoexecute ut_test;
12-
reporter ut_suite_reporter;
1320
begin
1421
suite1 := ut_test_suite(a_suite_name => 'Test Suite 1' /*,a_items => ut_test_objects_list()*/);
1522

@@ -32,14 +39,8 @@ begin
3239
suite_complex := ut_test_suite(a_suite_name => 'Complex Test Suite', a_items => ut_test_objects_list(suite1, suite2));
3340

3441
-- provide a reporter to process results
35-
--reporter := ut_dbms_output_suite_reporter;
36-
reporter := ut_custom_reporter(a_tab_size => 2);
37-
suite_complex.execute(reporter);
42+
suite_complex.execute(ut_custom_reporter(a_tab_size => 2));
3843
end;
3944
/
4045

41-
42-
43-
44-
45-
46+
drop type ut_custom_reporter;

examples/RunExampleTestSuite.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
44
Clear Screen
5-
Set Serveroutput On Size Unlimited
5+
Set Serveroutput On Size Unlimited format truncated
6+
set echo off
7+
--install the example unit test packages
8+
@@ut_exampletest.pks
9+
@@ut_exampletest.pkb
10+
@@ut_exampletest2.pks
11+
@@ut_exampletest2.pkb
612

713
declare
814
suite ut_test_suite;

examples/RunExampleTestSuiteWithCustomDBMSOutputReporter.sql

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
44
Clear Screen
5-
Set Serveroutput On Size Unlimited
5+
Set Serveroutput On Size Unlimited format truncated --http://stackoverflow.com/questions/2584492/how-to-prevent-dbms-output-put-line-from-trimming-leading-whitespace
6+
set echo off
7+
--install the example unit test packages
8+
@@ut_exampletest.pks
9+
@@ut_exampletest.pkb
10+
@@ut_exampletest2.pks
11+
@@ut_exampletest2.pkb
12+
@@ut_custom_reporter.tps
13+
@@ut_custom_reporter.tpb
614

715
declare
816
suite ut_test_suite;
917
testtoexecute ut_test;
10-
reporter ut_suite_reporter;
1118
begin
1219
-- Install ut_custom_reporter first from example folder
1320

@@ -28,7 +35,9 @@ begin
2835
suite.add_item(testtoexecute);
2936

3037
-- provide a reporter to process results tabbing each hierarcy level by tab_size
31-
reporter := ut_custom_reporter(a_tab_size => 2);
32-
suite.execute(reporter);
38+
suite.execute(ut_custom_reporter(a_tab_size => 2));
3339
end;
3440
/
41+
42+
43+
drop type ut_custom_reporter;

examples/RunExampleTestSuiteWithDBMSOutputReporter.sql

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
44
Clear Screen
5-
Set Serveroutput On Size Unlimited
5+
Set Serveroutput On Size Unlimited format truncated
6+
set echo off
7+
--install the example unit test packages
8+
@@ut_exampletest.pks
9+
@@ut_exampletest.pkb
10+
@@ut_exampletest2.pks
11+
@@ut_exampletest2.pkb
612

713
declare
814
suite ut_test_suite;
915
testtoexecute ut_test;
10-
reporter ut_suite_reporter;
1116
begin
1217
suite := ut_test_suite(a_suite_name => 'Test Suite Name' /*,a_items => ut_test_objects_list()*/);
1318

@@ -26,13 +31,6 @@ begin
2631
suite.add_item(testtoexecute);
2732

2833
-- provide a reporter to process results
29-
reporter := ut_dbms_output_suite_reporter;
30-
suite.execute(reporter);
34+
suite.execute(ut_dbms_output_suite_reporter);
3135
end;
3236
/
33-
34-
35-
36-
37-
38-

examples/RunExampleTestThroughBaseClass.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
--This shows how the interna test engine works to test a single package.
22
--No tables are used for this and exceptions are handled better.
33
Clear Screen
4-
Set Serveroutput On Size Unlimited
4+
Set Serveroutput On Size Unlimited format truncated
5+
set echo off
6+
--install the example unit test packages
7+
@@ut_exampletest.pks
8+
@@ut_exampletest.pkb
59

610
declare
711
simple_test ut_test;

examples/ut_custom_reporter.tpb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
create or replace type body ut_custom_reporter is
2+
3+
constructor function ut_custom_reporter(a_tab_size integer default 4) return self as result is
4+
begin
5+
self.name := $$plsql_unit;
6+
self.lvl := 0;
7+
self.tab_size := a_tab_size;
8+
return;
9+
end;
10+
11+
member function tab(self in ut_custom_reporter) return varchar2 is
12+
tab_str varchar2(255);
13+
begin
14+
tab_str := rpad(' ', lvl * tab_size);
15+
return tab_str;
16+
end tab;
17+
18+
overriding member procedure print(msg varchar2) is
19+
begin
20+
(self as ut_dbms_output_suite_reporter).print(tab || msg);
21+
end print;
22+
23+
overriding member procedure begin_suite(self in out nocopy ut_custom_reporter, a_suite_name in varchar2) as
24+
begin
25+
(self as ut_dbms_output_suite_reporter).begin_suite(a_suite_name);
26+
lvl := lvl + 1;
27+
end;
28+
29+
overriding member procedure end_suite(self in out nocopy ut_custom_reporter, a_suite_name in varchar2, a_suite_execution_result in ut_execution_result) as
30+
begin
31+
lvl := lvl - 1;
32+
(self as ut_dbms_output_suite_reporter).end_suite(a_suite_name,a_suite_execution_result);
33+
end;
34+
35+
overriding member procedure begin_test(self in out nocopy ut_custom_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params) as
36+
begin
37+
(self as ut_dbms_output_suite_reporter).begin_test(a_test_name,a_test_call_params);
38+
lvl := lvl + 1;
39+
end;
40+
41+
overriding member procedure end_test(self in out nocopy ut_custom_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params, a_execution_result in ut_execution_result, a_assert_list in ut_assert_list) as
42+
begin
43+
lvl := lvl - 1;
44+
(self as ut_dbms_output_suite_reporter).end_test(a_test_name, a_test_call_params, a_execution_result, a_assert_list);
45+
end;
46+
47+
end;
48+
/

examples/ut_custom_reporter.tps

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
create or replace type ut_custom_reporter under ut_dbms_output_suite_reporter
2+
(
3+
lvl integer,
4+
tab_size integer,
5+
6+
-- Member functions and procedures
7+
constructor function ut_custom_reporter(a_tab_size integer default 4) return self as result,
8+
member function tab(self in ut_custom_reporter) return varchar2,
9+
overriding member procedure print(msg varchar2),
10+
overriding member procedure begin_suite(self in out nocopy ut_custom_reporter, a_suite_name in varchar2),
11+
overriding member procedure end_suite(self in out nocopy ut_custom_reporter, a_suite_name in varchar2, a_suite_execution_result in ut_execution_result),
12+
overriding member procedure begin_test(self in out nocopy ut_custom_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params),
13+
overriding member procedure end_test(self in out nocopy ut_custom_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params, a_execution_result in ut_execution_result, a_assert_list in ut_assert_list)
14+
)
15+
not final
16+
/

examples/ut_custom_reporter.typ

Lines changed: 0 additions & 70 deletions
This file was deleted.

source/types/ut_dbms_output_suite_reporter.tpb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ create or replace type body ut_dbms_output_suite_reporter is
22

33
static function c_dashed_line return varchar2 is
44
begin
5-
return '--------------------------------------------------------------------------------';
5+
return lpad('-',80,'-');
66
end;
77

88
constructor function ut_dbms_output_suite_reporter return self as result is
@@ -31,11 +31,6 @@ create or replace type body ut_dbms_output_suite_reporter is
3131
end;
3232

3333
overriding member procedure begin_test(self in out nocopy ut_dbms_output_suite_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params) as
34-
begin
35-
null;
36-
end;
37-
38-
overriding member procedure end_test(self in out nocopy ut_dbms_output_suite_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params, a_execution_result in ut_execution_result, a_assert_list in ut_assert_list) as
3934
begin
4035
print(ut_dbms_output_suite_reporter.c_dashed_line);
4136
if a_test_name is not null then
@@ -48,7 +43,10 @@ create or replace type body ut_dbms_output_suite_reporter is
4843
,a_test_call_params.object_name
4944
,a_test_call_params.test_procedure));
5045
end if;
51-
46+
end;
47+
48+
overriding member procedure end_test(self in out nocopy ut_dbms_output_suite_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params, a_execution_result in ut_execution_result, a_assert_list in ut_assert_list) as
49+
begin
5250
print('result: ' || a_execution_result.result_to_char);
5351
print('asserts');
5452
for i in a_assert_list.first .. a_assert_list.last loop

source/types/ut_dbms_output_suite_reporter.tps

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ create or replace type ut_dbms_output_suite_reporter force under ut_suite_report
99
member procedure print(msg varchar2),
1010

1111
overriding member procedure begin_suite(self in out nocopy ut_dbms_output_suite_reporter, a_suite_name in varchar2),
12-
overriding member procedure end_suite(self in out nocopy ut_dbms_output_suite_reporter, a_suite_name in varchar2, a_suite_execution_result in ut_execution_result),
1312
overriding member procedure begin_test(self in out nocopy ut_dbms_output_suite_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params),
14-
overriding member procedure end_test(self in out nocopy ut_dbms_output_suite_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params, a_execution_result in ut_execution_result, a_assert_list in ut_assert_list)
15-
13+
overriding member procedure end_test(self in out nocopy ut_dbms_output_suite_reporter, a_test_name in varchar2, a_test_call_params in ut_test_call_params, a_execution_result in ut_execution_result, a_assert_list in ut_assert_list),
14+
overriding member procedure end_suite(self in out nocopy ut_dbms_output_suite_reporter, a_suite_name in varchar2, a_suite_execution_result in ut_execution_result)
15+
1616
) not final
1717
/

0 commit comments

Comments
 (0)