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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/RunAllExamples.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Clear Screen
set echo off
set feedback off
prompt RunExampleComplexSuiteWithCustomDBMSOutputReporter
@@RunExampleComplexSuiteWithCustomDBMSOutputReporter.sql
prompt RunExampleTestSuite
@@RunExampleTestSuite.sql
prompt RunExampleTestSuiteWithCustomDBMSOutputReporter
@@RunExampleTestSuiteWithCustomDBMSOutputReporter.sql
prompt RunExampleTestSuiteWithDBMSOutputReporter
@@RunExampleTestSuiteWithDBMSOutputReporter.sql
prompt RunExampleTestThroughBaseClass
@@RunExampleTestThroughBaseClass.sql
prompt TestPackageName
@@TestPackageName.sql
prompt TestProcedureName
@@TestProcedureName.sql
prompt TestOwnerName
@@TestOwnerName.sql
prompt TestSetupProcedureName
@@TestSetupProcedureName.sql
prompt TestTeardownProcedureName
@@TestTeardownProcedureName.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--Shows how to create a test suite with the default reporter which is dbms_output
--No tables are used for this.
--Suite Management packages are when developed will make this easier.
Clear Screen
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off
--install the example unit test packages
Expand Down Expand Up @@ -36,11 +36,13 @@ begin

suite2.add_item(testtoexecute);

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

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

drop type ut_custom_reporter;
--drop type ut_custom_reporter;
drop package ut_exampletest;
drop package ut_exampletest2;
17 changes: 11 additions & 6 deletions examples/RunExampleTestSuite.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--Shows how to create a test suite in code and call the test runner.
--No tables are used for this.
--Suite Management packages are when developed will make this easier.
Clear Screen
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off
--install the example unit test packages
Expand All @@ -14,6 +14,7 @@ declare
suite ut_test_suite;
testtoexecute ut_test;
test_item ut_test;
assert ut_assert_result;
begin
suite := ut_test_suite(a_suite_name => 'Test Suite Name' /*,a_items => ut_test_objects_list()*/);

Expand All @@ -36,14 +37,18 @@ begin
for test_idx in suite.items.first .. suite.items.last loop
test_item := treat(suite.items(test_idx) as ut_test);
dbms_output.put_line('---------------------------------------------------');
dbms_output.put_line('Test:' || test_item.call_params.object_name || '.' || test_item.call_params.test_procedure);
dbms_output.put_line('Result: ' || test_item.execution_result.result_to_char);
dbms_output.put_line('Test:' || test_item.test.form_name);
dbms_output.put_line('Result: ' || test_item.result_to_char);
dbms_output.put_line('Assert Results:');
for i in test_item.assert_results.first .. test_item.assert_results.last loop
dbms_output.put_line(i || ' - result: ' || test_item.assert_results(i).result_to_char);
dbms_output.put_line(i || ' - Message: ' || test_item.assert_results(i).message);
for i in test_item.items.first .. test_item.items.last loop
assert := treat(test_item.items(i) as ut_assert_result);
dbms_output.put_line(i || ' - result: ' || assert.result_to_char);
dbms_output.put_line(i || ' - Message: ' || assert.message);
end loop;
end loop;
dbms_output.put_line('---------------------------------------------------');
end;
/

drop package ut_exampletest;
drop package ut_exampletest2;
10 changes: 7 additions & 3 deletions examples/RunExampleTestSuiteWithCustomDBMSOutputReporter.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--Shows how to create a test suite with the default reporter which is dbms_output
--No tables are used for this.
--Suite Management packages are when developed will make this easier.
Clear Screen
Set Serveroutput On Size Unlimited format truncated --http://stackoverflow.com/questions/2584492/how-to-prevent-dbms-output-put-line-from-trimming-leading-whitespace
--Clear Screen
--http://stackoverflow.com/questions/2584492/how-to-prevent-dbms-output-put-line-from-trimming-leading-whitespace
Set Serveroutput On Size Unlimited format truncated
set echo off
--install the example unit test packages
@@ut_exampletest.pks
Expand Down Expand Up @@ -40,4 +41,7 @@ end;
/


drop type ut_custom_reporter;
--FIXME this drop is causing issues when executing script several times within single session
--drop type ut_custom_reporter;
drop package ut_exampletest;
drop package ut_exampletest2;
5 changes: 4 additions & 1 deletion examples/RunExampleTestSuiteWithDBMSOutputReporter.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--Shows how to create a test suite with the default reporter which is dbms_output
--No tables are used for this.
--Suite Management packages are when developed will make this easier.
Clear Screen
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off
--install the example unit test packages
Expand Down Expand Up @@ -34,3 +34,6 @@ begin
suite.execute(ut_dbms_output_suite_reporter);
end;
/

drop package ut_exampletest;
drop package ut_exampletest2;
4 changes: 3 additions & 1 deletion examples/RunExampleTestThroughBaseClass.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--This shows how the interna test engine works to test a single package.
--No tables are used for this and exceptions are handled better.
Clear Screen
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off
--install the example unit test packages
Expand All @@ -23,3 +23,5 @@ begin
simple_test.execute(reporter);
end;
/

drop package ut_exampletest;
54 changes: 54 additions & 0 deletions examples/TestOwnerName.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--This shows how the interna test engine works to test a single package.
--No tables are used for this and exceptions are handled better.
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off

--Arrange
@@ut_exampletest.pks
@@ut_exampletest.pkb

PROMPT Does not report error when test owner name for a test is null
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'ut_exampletest'
,a_test_procedure => 'ut_exampletest'
,a_owner_name => null);

simple_test.execute();

--Assert
if simple_test.result != ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

PROMPT Reports error when test owner name for a test is invalid
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'ut_exampletest'
,a_test_procedure => 'ut_exampletest'
,a_owner_name => 'invalid owner name');

simple_test.execute();

--Assert
if simple_test.result = ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

--Cleanup
drop package ut_exampletest;
81 changes: 81 additions & 0 deletions examples/TestPackageName.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off

--Arrange
PROMPT Reports error when unit test package name for a test is null
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => null, a_test_procedure => 'ut_exampletest');

simple_test.execute();

--Assert
if simple_test.result = ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

--Arrange
PROMPT Reports error when unit test package name for a test is invalid
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'invalid test package name', a_test_procedure => 'ut_exampletest');

simple_test.execute();

--Assert
if simple_test.result = ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

--Arrange
PROMPT Reports error when unit test package for a test is in invalid state
begin
execute immediate
'create or replace package invalid_package is
v_variable non_existing_type;
procedure ut_exampletest;
end;';
exception when others then
if sqlcode = - 24344 then
dbms_output.put_line(' Invalid package created');
else
raise;
end if;
end;
/

declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'invalid_package', a_test_procedure => 'ut_exampletest');

simple_test.execute();

--Assert
if simple_test.result = ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

--Cleanup
drop package invalid_package;
52 changes: 52 additions & 0 deletions examples/TestProcedureName.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--This shows how the interna test engine works to test a single package.
--No tables are used for this and exceptions are handled better.
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off

--Arrange
@@ut_exampletest.pks
@@ut_exampletest.pkb

PROMPT Reports error when test procedure name for a test is null
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'ut_exampletest'
,a_test_procedure => null);

simple_test.execute();

--Assert
if simple_test.result = ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

PROMPT Reports error when test procedure name for a test is invalid
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'ut_exampletest'
,a_test_procedure => 'invalid procedure name');

simple_test.execute();

--Assert
if simple_test.result = ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

--Cleanup
drop package ut_exampletest;
54 changes: 54 additions & 0 deletions examples/TestSetupProcedureName.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--This shows how the interna test engine works to test a single package.
--No tables are used for this and exceptions are handled better.
--Clear Screen
Set Serveroutput On Size Unlimited format truncated
set echo off

--Arrange
@@ut_exampletest.pks
@@ut_exampletest.pkb

PROMPT Does not report error when test setup procedure name for a test is null
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'ut_exampletest'
,a_test_procedure => 'ut_exampletest'
,a_setup_procedure => null);

simple_test.execute();

--Assert
if simple_test.result != ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

PROMPT Reports error when test setup procedure name for a test is invalid
declare
simple_test ut_test;
begin

--Act
simple_test := ut_test(a_object_name => 'ut_exampletest'
,a_test_procedure => 'ut_exampletest'
,a_setup_procedure => 'invalid setup name');

simple_test.execute();

--Assert
if simple_test.result = ut_utils.tr_error then
dbms_output.put_line(' Success');
else
dbms_output.put_line(' Failure');
end if;
end;
/

--Cleanup
drop package ut_exampletest;
Loading