| |
|
Test any sort of expression with Quest Code Tester for Oracle
You can use the Expression test in the Test Builder to check for any sort of expression you like, not just a global variable defined in another package.
Flash tutorial explaining the topic: A brief video that shows you how to use Quest Code Tester to solve the problem posed by this topic. Step-by-step instructions: Follow these steps to replicate what we show you in the tutorial. Steps
From the Test Dashboard, create a new
test definition by
selecting New. Select
qctod#change_global from the list and press OK.
Click OK on the
Welcome to Test Builder dialog. Now you are inside Test Builder. Set up the test cases
Before diving into the details of
each of the test cases,
use "top down design" to brainstorm the various test cases that you
will need. You do this in the Test Case list. Press the "Add test case" button to
create a new test case. Do that for each of the following names:
Now it is time to provide the details
of each test case. For
each of the headers below, I assume that you will click on the
corresponding
test case name, and then shift focus to the Test Case Editor to fill in
the
blanks. Employee 100 bonus 1000
This test case will check the
contents of a global variable against
a specific expected value.
Dynamic check of 100 bonus 1000
Is this variation on the previous
test case, I don't
hard-code the expected value. Instead I call a function to retrieve the
current
salary. They should match.
qctod#employee_salary (100)
Time to save/run your test!
You can now save your test definition
and run your test with
a single press of the Save, Close, and Run button
in the Test Cases toolbar: You will then see the results in the
Results Viewer. Close
Results Viewer when finished viewing results. Source code of program tested: Compile this code in your schema so that you can build your test definition for it. CREATE OR REPLACE PACKAGE qctod#my_globals
IS
g_total_salary NUMBER;
END qctod#my_globals;
/
SHO ERR
CREATE OR REPLACE PROCEDURE qctod#change_global (
employee_id_in IN qctod#employees.employee_id%TYPE
, bonus_in IN NUMBER
)
IS
BEGIN
UPDATE qctod#employees
SET salary = salary + bonus_in
WHERE employee_id = employee_id_in
RETURNING salary
INTO qctod#my_globals.g_total_salary;
IF SQL%ROWCOUNT = 0
THEN
qctod#my_globals.g_total_salary := NULL;
END IF;
END qctod#change_global;
/
SHO ERR
CREATE OR REPLACE FUNCTION qctod#employee_salary (
employee_id_in IN qctod#employees.employee_id%TYPE
)
RETURN qctod#employees.salary%TYPE
IS
retval qctod#employees.salary%TYPE;
BEGIN
SELECT salary
INTO retval
FROM qctod#employees
WHERE employee_id = employee_id_in;
RETURN retval;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
RETURN NULL;
END qctod#employee_salary;
/
SHO ERR |
|