Home   PL/Unit - Test Driven Development for Oracle
                  |  Previous Page  |  Next Page
PL/Unit Assertions
                                                   
PL/Unit Assertions


PL/Unit Assertion Routines

     What follows is a comprehensive list of all available PL/Unit testing assertions from the plunit package and a description of their purpose.

Command line unit testing
     The following two subroutines can be used to execute PL/Unit from a command line environment like SQL*Plus.  The function returns a boolean indicating whether all tests passed.  Any failing tests will result in a false return value.

function run_all_tests(owner in varchar2, package_name in varchar2, show_output in boolean default true) return boolean;
procedure run_all_tests(owner in varchar2, package_name in varchar2, show_output in boolean default true);

PL/Unit Suites
procedure add_suite(owner in varchar2, package_name in varchar2)
Adds the package package_name owned by owner to the suite of tests linked to the current test package.  Calls to this procedure should be made inside a procedure named plunit_suite that exists in the current test package.  For more information, see PL/Unit Test Structure.

Assertion routines

Boolean assertions

procedure assert_true(condition in boolean, message in varchar2 default '')
Asserts that the condition is true.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_false(condition in boolean, message in varchar2 default '')
Asserts that the condition is false.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_equals(expected in boolean, actual in boolean, message in varchar2 default '')
Asserts that expected and actual are equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_equals(expected in boolean, actual in boolean, message in varchar2 default '')
Asserts that expected and actual are not equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_null(actual in boolean, message in varchar2 default '')
Asserts that the actual boolean is null.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_null(actual in boolean, message in varchar2 default '')
Asserts that the actual boolean is null.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

Varchar2 assertions

procedure assert_equals(expected in varchar2, actual in varchar2, message in varchar2 default '')
Asserts that expected and actual are equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_equals(expected in varchar2, actual in varchar2, message in varchar2 default '')
Asserts that expected and actual are not equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_null(actual in varchar2, message in varchar2 default '')
Asserts that actual is null.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_null(actual in varchar2, message in varchar2 default '')
Asserts that actual is not null.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_equals_value(query in varchar2, expected in varchar2, message in varchar2 default '')
Asserts that the result of query equals expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_not_equals_value(query in varchar2, expected in varchar2, message in varchar2 default '')
Asserts that the result of query does not equal expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

Date assertions

procedure assert_equals(expected in date, actual in date, message in varchar2 default '')
Asserts that expected and actual are equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_equals(expected in date, actual in date, message in varchar2 default '')
Asserts that expected and actual are not equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_null(actual in date, message in varchar2 default '')
Asserts that actual is null.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_null(actual in varchar2, message in varchar2 default '')
Asserts that actual is not null.  Use the varchar2 form of assert_not_null for date values.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_equals_value(query in varchar2, expected in date, message in varchar2 default '')
Asserts that the result of query equals expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_not_equals_value(query in varchar2, expected in date, message in varchar2 default '')
Asserts that the result of query does not equal expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

Number assertions

procedure assert_equals(expected in number, actual in number, message in varchar2 default '')
Asserts that expected and actual are equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_equals(expected in number, actual in number, range in number, message in varchar2 default '')
Asserts that expected and actual are within the specified range.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_equals(expected in number, actual in number, message in varchar2 default '')
Asserts that expected and actual are not equal.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_equals(expected in number, actual in number, range in number, message in varchar2 default '')
Asserts that expected and actual are not within the specified range.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_null(actual in date, message in varchar2 default '')
Asserts that actual is null.  Use the varchar2 form of assert_null for number values.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_not_null(actual in varchar2, message in varchar2 default '');
Asserts that actual is not null.  Use the varchar2 form of assert_not_null for number values.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_equals_value(query in varchar2, expected in number, message in varchar2 default '')
Asserts that the result of query equals expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_equals_value(query in varchar2, expected in number, range in number, message in varchar2 default '')
Asserts that the result of query is within range of expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_not_equals_value(query in varchar2, expected in number, message in varchar2 default '')
Asserts that the result of query does not equal expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_not_equals_value(query in varchar2, expected in number, range in number, message in varchar2 default '')
Asserts that the result of query is not within range of expected.  The query must return only one row and one column, or the assertion will fail.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

Other assertions

procedure fail(message in varchar2 default '')
Fail can be used to cause a test procedure to fail immediately using the supplied message.

procedure assert_object_exists(owner_in in varchar2, object_name_in in varchar2, object_type_in in varchar2, message in varchar2 default '')
Asserts that the database object object_name_in of type object_type_in and owned by owner_in exists.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_object_not_exists(owner_in in varchar2, object_name_in in varchar2, object_type_in in varchar2, message in varchar2 default '')
Asserts that the database object object_name_in of type object_type_in and owned by owner_in does not exist.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_equals(expected in varchar2, actual in varchar2, message in varchar2 default '')
Asserts that the results of the expected query contains the same result set as the results of the actual query.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_query_not_equals(expected in varchar2, actual in varchar2, message in varchar2 default '')
Asserts that the results of the expected query does not contain the same result set as the results of the actual query.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_raises_exception(plsql_call in varchar2, expected in number, message in varchar2 default '')
Asserts that the PL/SQL block passed in plsql_call raises the numeric exception expected.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.

procedure assert_raises_exception(plsql_call in varchar2, expected in varchar2, message in varchar2 default '')
Asserts that the PL/SQL block passed in plsql_call raises the named exception expected.  The optional message will be displayed if the assertion fails.  If not supplied, a default message is displayed.