How to generate a test case

The test case builder is part of the DBMS_SQLDIAG package. It can do a lot more than build test cases, the most basic functionality: how to generate the objects needed to run a SQL statement. Here’s a simple example, using the scott schema and a Windows server. There are numerous bad practices in the following, but it works. All from your SQL*Plus prompt.

Step 1: create a directory. The test case builder writes out a set of files to an Oracle directory. You need to create this, pointing to a suitable OS folder:

conn / as sysdba
host mkdir c:\tmp\diag
create directory diag as 'c:\tmp\diag';
grant all on directory diag to public;

Step 2: generate the test case files for your statement. This is one procedure call, by a user with suitable permissions:

conn / as sysdba
grant dba to scott;
conn scott/tiger
var tc clob
exec dbms_sqldiag.export_sql_testcase(directory=>'DIAG',sql_text=>'select * from emp natural join dept',testcase_name=>'mytest',testcase=>:tc)

Step 3: extract the DDL. From an OS prompt,

impdp scott/tiger directory=diag dumpfile=MYTESTDPEXP.DMP sqlfile=mytestddl.sql

Step 4: attach c:\tmp\diag\mytestddl.sql to your SR, or your topic on ORAfaq or the Oracle Forums.

This is merely a simple example, that will create the test schema with object statistics. Other options can include sample data, pl/sql source code, execution plans. You can read the docs to find out about all that:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_sqldiag.htm#

About Paras Shah

PARAS D. SHAH Email: parasshah04@gmail.com I’ve been working as Oracle DBA for more then 7+ years of experience. Known version: 7, 8i, 9i, 10g, 11, 12C Worked on: RAC, DATAGUARD, GOLDEN GATE,EBS suit, Backups and Restoration, Shell Scripts. Performance Tuning and analyzing database bottlenecks. Oracle Audit Vault and Database Firewall. Certifications:-  Oracle Database 11g Administrator Certified Associate. (OCA 11g)  Oracle Database 11g Administrator Certified Professional. (OCP 11g)  ITIL® Foundation Certificate in IT Service Management.
This entry was posted in Oracle DB and tagged , . Bookmark the permalink.

Leave a comment