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:

  • Employee 100 bonus 1000
  • Dynamic check of 100 bonus 1000

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.

  • Click on employee 100 bonus 1000 in the Test Case List
  • In the Input Grid enter "100" into EMPLOYEE_ID_IN (Employee 100 has a salary of 24000).  Enter "1000" into BONUS_IN
  • In the Outcome grid, right-click, choose Add outcome, then select "Expression" as the Changed by Program Type of Data.
  • Press […] in the Changed by Program field to bring up the Properties window.
  • Set the Base data type to NUMBER.
  • Type "qctod#my_globals.g_total_salary" into the "Code that is assigned…" field.
  • Press OK.
  • Set operator to "= " (equal to) and Expected Results datatype to NUMBER.
  • Type 25000 into the Expected Results value field.
  • Next test case!

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.

  • Click on Dynamic check of 100 bonus 1000 in the Test Case List
  • Input: enter "100" into EMPLOYEE_ID_IN (Employee 100 has a salary of 24000).
  • Enter "1000" into BONUS_IN
  • In the Outcome grid right-click on Select Add Outcome, select "Expression" as the Changed by Program Type of Data.
  • Press […] in the Change by Program Value Field to bring up the Properties window.
  • Set the Base data type to NUMBER.
  • Type "qctod#my_globals.g_total_salary" into the "Code that is assigned…" field.
  • Press OK.
  • Set operator to "= " (equal to) and Expected Results datatype to NUMBER.
  • Press […] in the Expected Results Value field to bring up the Properties window.
  • Select the Single Value Expression Radio button.
  • Click on the "Evaluate as expression" checkbox on the bottom.
  • Type the following code into the field:

            qctod#employee_salary (100)

  • Press OK, and all done!

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