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

Skip to content

Commit 49304c3

Browse files
committed
Class model rework based on discussion with @jgebal
. All the hierarchy now is formed from ut_object class, asserts, tests and suite are homogeneous by composite pattern. Lots of new tests/examples added Composite reporter class added to use multiple reporters simultaneously reporters now accept ut_object (ut_suite, ut_test, ut_assert) as an input and are statefull Some classes where dropped.
2 parents f50a4e9 + 7da9de2 commit 49304c3

46 files changed

Lines changed: 752 additions & 357 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/RunAllExamples.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Clear Screen
2+
set echo off
3+
set feedback off
4+
prompt RunExampleComplexSuiteWithCustomDBMSOutputReporter
5+
@@RunExampleComplexSuiteWithCustomDBMSOutputReporter.sql
6+
prompt RunExampleTestSuite
7+
@@RunExampleTestSuite.sql
8+
prompt RunExampleTestSuiteWithCustomDBMSOutputReporter
9+
@@RunExampleTestSuiteWithCustomDBMSOutputReporter.sql
10+
prompt RunExampleTestSuiteWithDBMSOutputReporter
11+
@@RunExampleTestSuiteWithDBMSOutputReporter.sql
12+
prompt RunExampleTestThroughBaseClass
13+
@@RunExampleTestThroughBaseClass.sql
14+
prompt TestPackageName
15+
@@TestPackageName.sql
16+
prompt TestProcedureName
17+
@@TestProcedureName.sql
18+
prompt TestOwnerName
19+
@@TestOwnerName.sql
20+
prompt TestSetupProcedureName
21+
@@TestSetupProcedureName.sql
22+
prompt TestTeardownProcedureName
23+
@@TestTeardownProcedureName.sql

examples/RunExampleComplexSuiteWithCustomDBMSOutputReporter.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--Shows how to create a test suite with the default reporter which is dbms_output
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
4-
Clear Screen
4+
--Clear Screen
55
Set Serveroutput On Size Unlimited format truncated
66
set echo off
77
--install the example unit test packages
@@ -36,11 +36,13 @@ begin
3636

3737
suite2.add_item(testtoexecute);
3838

39-
suite_complex := ut_test_suite(a_suite_name => 'Complex Test Suite', a_items => ut_test_objects_list(suite1, suite2));
39+
suite_complex := ut_test_suite(a_suite_name => 'Complex Test Suite', a_items => ut_objects_list(suite1, suite2));
4040

4141
-- provide a reporter to process results
4242
suite_complex.execute(ut_custom_reporter(a_tab_size => 2));
4343
end;
4444
/
4545

46-
drop type ut_custom_reporter;
46+
--drop type ut_custom_reporter;
47+
drop package ut_exampletest;
48+
drop package ut_exampletest2;

examples/RunExampleTestSuite.sql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--Shows how to create a test suite in code and call the test runner.
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
4-
Clear Screen
4+
--Clear Screen
55
Set Serveroutput On Size Unlimited format truncated
66
set echo off
77
--install the example unit test packages
@@ -14,6 +14,7 @@ declare
1414
suite ut_test_suite;
1515
testtoexecute ut_test;
1616
test_item ut_test;
17+
assert ut_assert_result;
1718
begin
1819
suite := ut_test_suite(a_suite_name => 'Test Suite Name' /*,a_items => ut_test_objects_list()*/);
1920

@@ -36,14 +37,18 @@ begin
3637
for test_idx in suite.items.first .. suite.items.last loop
3738
test_item := treat(suite.items(test_idx) as ut_test);
3839
dbms_output.put_line('---------------------------------------------------');
39-
dbms_output.put_line('Test:' || test_item.call_params.object_name || '.' || test_item.call_params.test_procedure);
40-
dbms_output.put_line('Result: ' || test_item.execution_result.result_to_char);
40+
dbms_output.put_line('Test:' || test_item.test.form_name);
41+
dbms_output.put_line('Result: ' || test_item.result_to_char);
4142
dbms_output.put_line('Assert Results:');
42-
for i in test_item.assert_results.first .. test_item.assert_results.last loop
43-
dbms_output.put_line(i || ' - result: ' || test_item.assert_results(i).result_to_char);
44-
dbms_output.put_line(i || ' - Message: ' || test_item.assert_results(i).message);
43+
for i in test_item.items.first .. test_item.items.last loop
44+
assert := treat(test_item.items(i) as ut_assert_result);
45+
dbms_output.put_line(i || ' - result: ' || assert.result_to_char);
46+
dbms_output.put_line(i || ' - Message: ' || assert.message);
4547
end loop;
4648
end loop;
4749
dbms_output.put_line('---------------------------------------------------');
4850
end;
4951
/
52+
53+
drop package ut_exampletest;
54+
drop package ut_exampletest2;

examples/RunExampleTestSuiteWithCustomDBMSOutputReporter.sql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
--Shows how to create a test suite with the default reporter which is dbms_output
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
4-
Clear Screen
5-
Set Serveroutput On Size Unlimited format truncated --http://stackoverflow.com/questions/2584492/how-to-prevent-dbms-output-put-line-from-trimming-leading-whitespace
4+
--Clear Screen
5+
--http://stackoverflow.com/questions/2584492/how-to-prevent-dbms-output-put-line-from-trimming-leading-whitespace
6+
Set Serveroutput On Size Unlimited format truncated
67
set echo off
78
--install the example unit test packages
89
@@ut_exampletest.pks
@@ -40,4 +41,7 @@ end;
4041
/
4142

4243

43-
drop type ut_custom_reporter;
44+
--FIXME this drop is causing issues when executing script several times within single session
45+
--drop type ut_custom_reporter;
46+
drop package ut_exampletest;
47+
drop package ut_exampletest2;

examples/RunExampleTestSuiteWithDBMSOutputReporter.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--Shows how to create a test suite with the default reporter which is dbms_output
22
--No tables are used for this.
33
--Suite Management packages are when developed will make this easier.
4-
Clear Screen
4+
--Clear Screen
55
Set Serveroutput On Size Unlimited format truncated
66
set echo off
77
--install the example unit test packages
@@ -34,3 +34,6 @@ begin
3434
suite.execute(ut_dbms_output_suite_reporter);
3535
end;
3636
/
37+
38+
drop package ut_exampletest;
39+
drop package ut_exampletest2;

examples/RunExampleTestThroughBaseClass.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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.
3-
Clear Screen
3+
--Clear Screen
44
Set Serveroutput On Size Unlimited format truncated
55
set echo off
66
--install the example unit test packages
@@ -23,3 +23,5 @@ begin
2323
simple_test.execute(reporter);
2424
end;
2525
/
26+
27+
drop package ut_exampletest;

examples/TestOwnerName.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--This shows how the interna test engine works to test a single package.
2+
--No tables are used for this and exceptions are handled better.
3+
--Clear Screen
4+
Set Serveroutput On Size Unlimited format truncated
5+
set echo off
6+
7+
--Arrange
8+
@@ut_exampletest.pks
9+
@@ut_exampletest.pkb
10+
11+
PROMPT Does not report error when test owner name for a test is null
12+
declare
13+
simple_test ut_test;
14+
begin
15+
16+
--Act
17+
simple_test := ut_test(a_object_name => 'ut_exampletest'
18+
,a_test_procedure => 'ut_exampletest'
19+
,a_owner_name => null);
20+
21+
simple_test.execute();
22+
23+
--Assert
24+
if simple_test.result != ut_utils.tr_error then
25+
dbms_output.put_line(' Success');
26+
else
27+
dbms_output.put_line(' Failure');
28+
end if;
29+
end;
30+
/
31+
32+
PROMPT Reports error when test owner name for a test is invalid
33+
declare
34+
simple_test ut_test;
35+
begin
36+
37+
--Act
38+
simple_test := ut_test(a_object_name => 'ut_exampletest'
39+
,a_test_procedure => 'ut_exampletest'
40+
,a_owner_name => 'invalid owner name');
41+
42+
simple_test.execute();
43+
44+
--Assert
45+
if simple_test.result = ut_utils.tr_error then
46+
dbms_output.put_line(' Success');
47+
else
48+
dbms_output.put_line(' Failure');
49+
end if;
50+
end;
51+
/
52+
53+
--Cleanup
54+
drop package ut_exampletest;

examples/TestPackageName.sql

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
--Clear Screen
2+
Set Serveroutput On Size Unlimited format truncated
3+
set echo off
4+
5+
--Arrange
6+
PROMPT Reports error when unit test package name for a test is null
7+
declare
8+
simple_test ut_test;
9+
begin
10+
11+
--Act
12+
simple_test := ut_test(a_object_name => null, a_test_procedure => 'ut_exampletest');
13+
14+
simple_test.execute();
15+
16+
--Assert
17+
if simple_test.result = ut_utils.tr_error then
18+
dbms_output.put_line(' Success');
19+
else
20+
dbms_output.put_line(' Failure');
21+
end if;
22+
end;
23+
/
24+
25+
--Arrange
26+
PROMPT Reports error when unit test package name for a test is invalid
27+
declare
28+
simple_test ut_test;
29+
begin
30+
31+
--Act
32+
simple_test := ut_test(a_object_name => 'invalid test package name', a_test_procedure => 'ut_exampletest');
33+
34+
simple_test.execute();
35+
36+
--Assert
37+
if simple_test.result = ut_utils.tr_error then
38+
dbms_output.put_line(' Success');
39+
else
40+
dbms_output.put_line(' Failure');
41+
end if;
42+
end;
43+
/
44+
45+
--Arrange
46+
PROMPT Reports error when unit test package for a test is in invalid state
47+
begin
48+
execute immediate
49+
'create or replace package invalid_package is
50+
v_variable non_existing_type;
51+
procedure ut_exampletest;
52+
end;';
53+
exception when others then
54+
if sqlcode = - 24344 then
55+
dbms_output.put_line(' Invalid package created');
56+
else
57+
raise;
58+
end if;
59+
end;
60+
/
61+
62+
declare
63+
simple_test ut_test;
64+
begin
65+
66+
--Act
67+
simple_test := ut_test(a_object_name => 'invalid_package', a_test_procedure => 'ut_exampletest');
68+
69+
simple_test.execute();
70+
71+
--Assert
72+
if simple_test.result = ut_utils.tr_error then
73+
dbms_output.put_line(' Success');
74+
else
75+
dbms_output.put_line(' Failure');
76+
end if;
77+
end;
78+
/
79+
80+
--Cleanup
81+
drop package invalid_package;

examples/TestProcedureName.sql

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--This shows how the interna test engine works to test a single package.
2+
--No tables are used for this and exceptions are handled better.
3+
--Clear Screen
4+
Set Serveroutput On Size Unlimited format truncated
5+
set echo off
6+
7+
--Arrange
8+
@@ut_exampletest.pks
9+
@@ut_exampletest.pkb
10+
11+
PROMPT Reports error when test procedure name for a test is null
12+
declare
13+
simple_test ut_test;
14+
begin
15+
16+
--Act
17+
simple_test := ut_test(a_object_name => 'ut_exampletest'
18+
,a_test_procedure => null);
19+
20+
simple_test.execute();
21+
22+
--Assert
23+
if simple_test.result = ut_utils.tr_error then
24+
dbms_output.put_line(' Success');
25+
else
26+
dbms_output.put_line(' Failure');
27+
end if;
28+
end;
29+
/
30+
31+
PROMPT Reports error when test procedure name for a test is invalid
32+
declare
33+
simple_test ut_test;
34+
begin
35+
36+
--Act
37+
simple_test := ut_test(a_object_name => 'ut_exampletest'
38+
,a_test_procedure => 'invalid procedure name');
39+
40+
simple_test.execute();
41+
42+
--Assert
43+
if simple_test.result = ut_utils.tr_error then
44+
dbms_output.put_line(' Success');
45+
else
46+
dbms_output.put_line(' Failure');
47+
end if;
48+
end;
49+
/
50+
51+
--Cleanup
52+
drop package ut_exampletest;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--This shows how the interna test engine works to test a single package.
2+
--No tables are used for this and exceptions are handled better.
3+
--Clear Screen
4+
Set Serveroutput On Size Unlimited format truncated
5+
set echo off
6+
7+
--Arrange
8+
@@ut_exampletest.pks
9+
@@ut_exampletest.pkb
10+
11+
PROMPT Does not report error when test setup procedure name for a test is null
12+
declare
13+
simple_test ut_test;
14+
begin
15+
16+
--Act
17+
simple_test := ut_test(a_object_name => 'ut_exampletest'
18+
,a_test_procedure => 'ut_exampletest'
19+
,a_setup_procedure => null);
20+
21+
simple_test.execute();
22+
23+
--Assert
24+
if simple_test.result != ut_utils.tr_error then
25+
dbms_output.put_line(' Success');
26+
else
27+
dbms_output.put_line(' Failure');
28+
end if;
29+
end;
30+
/
31+
32+
PROMPT Reports error when test setup procedure name for a test is invalid
33+
declare
34+
simple_test ut_test;
35+
begin
36+
37+
--Act
38+
simple_test := ut_test(a_object_name => 'ut_exampletest'
39+
,a_test_procedure => 'ut_exampletest'
40+
,a_setup_procedure => 'invalid setup name');
41+
42+
simple_test.execute();
43+
44+
--Assert
45+
if simple_test.result = ut_utils.tr_error then
46+
dbms_output.put_line(' Success');
47+
else
48+
dbms_output.put_line(' Failure');
49+
end if;
50+
end;
51+
/
52+
53+
--Cleanup
54+
drop package ut_exampletest;

0 commit comments

Comments
 (0)