[ Home | Getting Started | Build Test Packages | Examples | User Guide | Release Notes | Document Map ]
< Previous Section: Test a Procedure | Next Section: Test an Entire Package API >
As with the procedure, there are a couple of scenarios to consider:
First, a test of a function returning a scalar value. Consider the following packaged function:
/*file str.pks and str.pkb */
CREATE OR REPLACE PACKAGE str
IS
FUNCTION betwn (
string_in IN VARCHAR2,
start_in IN PLS_INTEGER,
end_in IN PLS_INTEGER
)
RETURN VARCHAR2;
END str;
/
The str.betwn function returns the sub-string of a string_in that is found between the start and end locations specified by start_in and end_in.
So...time to test! I generate a test package and then modify the unit test procedure to check for various conditions:
/*file ut_str.pkb */
CREATE OR REPLACE PACKAGE BODY ut_str
IS
PROCEDURE ut_setup
IS
BEGIN
NULL;
END;
PROCEDURE ut_teardown
IS
BEGIN
NULL;
END;
-- For each program to test...
PROCEDURE ut_betwn IS
BEGIN
utAssert.eq (
'Typical Valid Usage',
str.betwn ('this is a string', 3, 7),
'is is'
);
utAssert.eq (
'Test Negative Start',
str.betwn ('this is a string', -3, 7),
'ing'
);
utAssert.isNULL (
'Start bigger than end',
str.betwn ('this is a string', 3, 1)
);
END ut_betwn;
END ut_str;
/
As you can see, my calls to str.betwn are embedded right within calls to utAssert.eq and utAssert.isNULL, making my test code compact.
< Previous Section: Test a Procedure | Next Section: Test an Entire Package API >
Copyright © 2000-2005, 2014-2016 Steven Feuerstein, Chris Rimmer, Patrick Barel and the utPLSQL Project. All rights reserved