| |
|
Does the program raise a specific exception or any exception?
We generally don't want or expect our programs to raise exceptions. But under certain circumstances, that is exactly what should happen, and we need to test for that. This tutorial shows how to check for an exception by name or error code.
You can also check to see if your program raised any exception at all (rather than a specific exception. The default testing behavior is that if an exception is raised, Quest Code Tester for Oracle records this is a runtime error, rather than a logical failure.
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, ask to create a new test definition by selecting New from the Test Definitions for program right-click menu. Select qctod#test_exceptions from the list and press OK. Click OK on the Welcome to Test Builder screen. Now you are inside Test Builder. Set up the test casesBefore 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 and rename the test case used with 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 in the Test Case List, and then shift focus to the Test Case Editor to edit the input and output grids. Check for any errorsIn this test case, we will check to see if the program raises any exception, it doesn't matter which. This constitutes a failed test.
No errors raised at allThe program fails if it does not raise any exceptions! Sure, why not….
Raise -20000My program uses RAISE_APPLICATION_ERROR to raise an application error in the -20000 to -20999 range. Need to be able to check for these as well.
Raise NO_DATA_FOUNDUh oh, I might be doing a SELECT INTO in my program and I know I don't handle NO_DATA_FOUND. Let's test for that.
Divide by zeroMy program doesn't raise this error. Oracle raises it when I try to divide by zero. Let's test for that.
Time to run your test!When you have gone through each of the test cases, press the Save, Close and Run button to close Test Builder, return to Test Dashboard and immediately run your test. Quest Code Tester for Oracle will then save your definition to the repository, and run your test. You should see the Results Viewer and a green flag, indicating a successful run. Source code of program tested: Compile this code in your schema so that you can build your test definition for it. CREATE OR REPLACE PROCEDURE test_exceptions (
raise_ndf_in IN BOOLEAN DEFAULT FALSE
, raise_20000_in IN BOOLEAN DEFAULT FALSE
, raise_unknown_in IN BOOLEAN DEFAULT FALSE
, raise_nothing_in IN BOOLEAN DEFAULT FALSE
, cause_div_by_zero_in IN BOOLEAN DEFAULT FALSE
)
IS
BEGIN
CASE
WHEN raise_ndf_in
THEN
RAISE NO_DATA_FOUND;
WHEN raise_20000_in
THEN
raise_application_error (-20000, 'I raised -20000 deliberately');
WHEN raise_unknown_in
THEN
RAISE UTL_FILE.file_open;
WHEN raise_nothing_in
THEN
DBMS_OUTPUT.put_line ('No problems here!');
WHEN cause_div_by_zero_in
THEN
DBMS_OUTPUT.put_line (1 / 0);
END CASE;
END test_exceptions;
/
SHO ERR |
|