| |
|
Tips for working with object types in Quest Code Tester
Support for object types in the current release of Quest Code Tester is limited. Check out this tutorial for tips on how to best work with object types as arguments and outcomes.
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. StepsFrom the Test Dashboard, create a new test definition by selecting New. Select qctod#out_object from the list and press OK. Click OK on the Welcome to Test Builder dialog. Now you are inside Test Builder. Define the test caseCreate a new test case called "Return object" by pressing on the "Add test case" button to create a new test case. Next, type in the value of "Larry" for the first name argument and "Ellison" for the last name argument. Now define the outcome. Click into the empty Outcome Grid, choose Add outcome. Then under Changed by Program, click on the down arrow and choose Expression from the list. Then press the [...] button to bring up the Properties window. Set the datatype to Boolean and type this information into the code box at the bottom of the window: qctod#names_eq (from_program, l_expected) In other words, we will call the equality check function and pass it two objects. One object is coming from the program, the other is the expected object we will define. You could, actually, use whatever names you want for those two variables, as in: qctod#names_eq (A, B) We are going to change the from_program name in a moment anyway. Press OK and make sure the Operator is set to "Evaluates to TRUE". Then press the Save and Close button (Save disk icon) in the top left toolbar of Test Builder. You will now be returned to the Test Dashboard. Double click on the program name and enter Test Editor. Fine-tune the test caseYou've created the test case, but it needs to be polished up quite a bit. So far, we have a Boolean outcome that checks the value returned by the function. We now need to: a. Initialize the "expected" object to have the attribute values we expect. b. Find the correct name for the object returned by the procedure. To take care of (a), do the following: 1. Drill down in Test Editor to the test case. Click on the name. To the right, you will see a Customizations tab. Click on that. 2. Click on the + next to "Declarations of custom non-program elements" and enter this code: l_expected qctod#name_type; 3. Open up the "Initialization" section on the screen and enter this code: l_expected := qctod#name_type('Larry', 'Ellison'); Excellent! Now we have defined the expected object with the correct first and last names. To take care of (b) (find the correct name for the object returned by the procedure), do the following: 1. Drill down to the outcome of the test case. 2. Click on the Program Call tab on the right hand side. 3. Copy the name of the variable that is receiving the name_object_out variable. It should be: p_name_object_out 4. Click on the From Program tab of the outcome and change the code there to: qctod#names_eq (p_name_object_out, l_expected) Notice how the names of the two inputs now match the variables that we defined (l_expected) and is used by the program (p_name_object_out). Time to run your test!You can now click on the Run button in the Test Editor toolbar, and you should see a green face. If you now go back to the test case initialization section and change the first name to "George" or anything else, re-run your test, you should see a failure. So...there's nothing elegant about this, but you can get the job done, and still keep all of your test logic in the Quest Code Tester repository. Source code of program tested: Compile this code in your schema so that you can build your test definition for it. CREATE OR REPLACE TYPE qctod#name_type IS OBJECT (
firstname VARCHAR2 (20)
, lastname VARCHAR2 (20)
, MEMBER FUNCTION full_name (SELF IN OUT qctod#name_type)
RETURN VARCHAR2
)
/
CREATE OR REPLACE TYPE BODY qctod#name_type
AS
MEMBER FUNCTION full_name (SELF IN OUT qctod#name_type)
RETURN VARCHAR2
IS
BEGIN
RETURN SELF.firstname || ' ' || SELF.lastname;
END;
END;
/
CREATE OR REPLACE PROCEDURE qctod#out_object (
firstname_in IN VARCHAR2
, lastname_in IN VARCHAR2
, name_object_out OUT qctod#name_type
)
IS
l_object qctod#name_type := qctod#name_type (firstname_in, lastname_in);
BEGIN
name_object_out := l_object;
END qctod#out_object;
/
CREATE OR REPLACE FUNCTION qctod#names_eq (
p_names1_i IN qctod#name_type
, p_names2_i IN qctod#name_type
)
RETURN BOOLEAN
IS
RESULT BOOLEAN;
fn VARCHAR2 (500);
LN VARCHAR2 (500);
BEGIN
RETURN ( ( p_names1_i.firstname = p_names2_i.firstname
OR ( p_names1_i.firstname IS NULL
AND p_names2_i.firstname IS NULL
)
)
AND ( p_names1_i.lastname = p_names2_i.lastname
OR (p_names1_i.lastname IS NULL
AND p_names2_i.lastname IS NULL
)
)
);
END qctod#names_eq;
/ |
|