SlideShare a Scribd company logo
Tarik R. Essawi
VeriSign Inc.
Agile Database Testing Techniques
Introduction
• Real world best practices
• Proven Techniques
• Why Test ?
• How to greatly improve
– PL/SQL Quality
– Database Schema Installations
– Reports
– Build Process
– Debugging and Monitoring
Why Test ?
• You will spend time testing your code.
– You can manually test your code every time a
change is made or a build is deployed
• Manual testing is haphazard
• Code coverage is sporadic at best
– You can create an automated unit test once that
can be run every time the code changes
• Tests are repeatable
• Code Coverage is repeatable
Finding Defects
• Defects will be found, the only question is
when:
– Options
1)You can find the defects during
development
2)Quality Assurance can find the defects
3)Customers can find the defects in
production
What is Agility
• A rapid change of velocity or direction in
response to a stimulus
• Many different forms and methods
– Test Driven Development
– Extreme Programming
– Scrum
• Foundation of Agility is Testing
– Creates confidence to change direction
Traditional QA role
• Responsible for finding defects
• If defects are not found in QA they are found
in production
A Different Approach
• Guilty Until Proven Innocent
• Developers must prove code is correct
• QA role becomes:
– Corroborate test results
– Verify the Delivered Code meets Requirements
– Focus on integration tests of corner cases
Side Effects
• Number of builds reduced
• Amount of rework reduced
Week0
Week1
Week2
Week3
Week4
Week5
Week6
Week7
Week8
0
5
10
15
20
25
30
35
40
Time
Man Hours
Development Lifecycle
Automated Testing
Maual Testing
PL/SQL Testing
UtPlsql Installation
• UtPlsql is a plsql unit testing framework. It is one of many, So if
you are not using plsql other testing frameworks exist that
accomplish the same goal.
• Installing the package
– Download zip file from
• http://utplsqlsql.sourceforge.net
• Unzip the file.
– Create user
• connect to the database as system
• create user utplsql identified by utplsql default tablespace ?? temporary
tablespace ??;
• grant create session, create table, create procedure, create sequence,
create view, create public synonym, drop public synonym to utplsql;
• alter user utplsql quota unlimited on ??;
• You can also just grant DBA privileges.
– In the code directory where the file is unzipped, login to sqlplus as
utplsql and run @ut_i_do install (you must pass in the parameter
“install”).
– Create public synonyms for all of the packages owned by utplsql.
Developing the Tests
• A test package is created for each application
package
– For example, to test PKGORDERITEMS a
package called UT_ PKGORDERITEMS is
created
• Each package contains a ut_setup,
ut_teardown, and then individual procedures
to test the code
• The tests are self-contained
• Tests are based on assertions
Assertions
• Assertions are the heart of the testing framework
• You will prove through the assertion that the results are correct
• Below are the basic assertions that can satisfy 80% of test cases.
– utassert.eqquery – compares multiple columns of two queries or result sets
– utassert.eqqueryvalue – compares a single column returned from a query
– utassert.eq –compares two values
– utassert.throws – is used to test that exceptions are being thrown and
caught properly
• For the other 20% you can also
– Compare tables, pipes, refcursors, and collections for equality
– Check for null values, table counts and whether previous assertions passed
or failed
– You can also extend the assert procedure through inheritance and create
your own
Running Tests
• Compile the test package under the same
schema as the calling package
• Run the test by calling utplsql.test. This is
one of many ways to execute the test
SET SERVEROUTPUT ON SIZE UNLIMITED
BEGIN
utplsql.test(package_in=>'PKGORDERITEMS',
recompile_in=>FALSE);
DBMS_OUTPUT.put_line (utplsql2.runnum);
END;
Running Tests Con’t
• Review the output, which will say
> SSSS U U CCC CCC EEEEEEE SSSS SSSS
> S S U U C C C C E S S S S
> S U U C C C C E S S
> S U U C C E S S
> SSSS U U C C EEEE SSSS SSSS
> S U U C C E S S
> S U U C C C C E S S
> S S U U C C C C E S S S S
> SSSS UUU CCC CCC EEEEEEE SSSS SSSS
OR
> FFFFFFF AA III L U U RRRRR EEEEEEE
> F A A I L U U R R E
> F A A I L U U R R E
> F A A I L U U R R E
> FFFF A A I L U U RRRRRR EEEE
> F AAAAAAAA I L U U R R E
> F A A I L U U R R E
> F A A I L U U R R E
> F A A III LLLLLLL UUU R R EEEEEEE
.
Database Schema Installs
Install Uninstall Procedures
• Install and Uninstall scripts should not require any operator input
• Script should be simple and straightforward
spool install.lst
PROMPT Calling define_var.sql...
@@define_var.sql
/*********************************************
* Creating Orders
**********************************************/
@cr_orders.sql
/*********************************************
* Creating OrderItems
**********************************************/
@cr_order_items_table.sql
spool off;
!grep 'ORA-' *.lst
!grep 'SP2-' *.lst
exit
Validating Schema Installs
• Schema installs are one-time tasks where quality is
extremely critical
• Errors during a schema install can cause an entire
release to be rolled back or cause the maintenance
window to be missed due to debugging
• Validation scripts evolved based on the following
scenarios:
– Errors being written to files and never reviewed
– Errors never being written to files at all
– Scripts not executing, which means no error is generated
– Scripts that exit part of the way through and never execute
the remaining commands
Validating Schema Installs con’t
• Verify that every object that was expected to be
created actually exists.
• Create an assertion package that will verify the actual
versus the expected.
• Generate an error if the assertion fails.
• Items to check
– Tables
– Indexes
– Constraints
– Synonyms and Grants
– Reference data was inserted or updated as expected
– Anything created during the install…
Schema Install Validation Example
• Below is an example of a database verification script. The assertion procedure was written
in-house and raises an error if the first and second parameters are not equal. The
verification script are tailored to each deployment.
declare
v_actual number;
Begin
-- Verify TABLE Tables
select count(*) into v_actual from user_tables
where table_name = ‘ORDER_ITEMS'
and tablespace_name = 'DATA';
PkgValidation.assert(1, v_actual,' Verify Order Items');
-- Verify TABLE INDEXES
select count(*) into v_actual from user_indexes
where index_name in
('IDX_ORDER_ITEMS',
'PK_ORDER_ITEMS')
and tablespace_name = 'INDEX';
PkgValidation.assert(2, v_actual,' Verify Index Creation');
-- Print Validation Summary
dbms_output.put_line('=======================================================');
dbms_output.put_line('**Assertions passed : '||PkgValidation.v_assertions_passed);
dbms_output.put_line('**Assertions Failed : '||PkgValidation.v_assertions_failed);
dbms_output.put_line('**Total Assertions : '||PkgValidation.v_total_assertions);
dbms_output.put_line('=======================================================');
end;
Report Testing
• Report Testing can be challenging:
– Reports contain millions of rows
– A single report can consist of multiple pages of SQL Code
• Automating Report Testing can be accomplished:
– Load the report into the database using sqlloader or external
tables
– Once the report is accessible within the database the source
data can be compared to the report data
– Assertions can be used to compare each record in the report
with the source data and vice versa
– This initial testing will identify common errors with complex
table joins and date ranges
– Controlled Datasets will validate the end to end testing of the
system from the customer channel through to the reports
Daily Builds
Daily Build Database
• The development and test environments must
be functionally equivalent to production
• The hardware can differ but the logical
structure of the database must be an exact
replica
• Use the DBMS_METADATA package
DBMS_METADATA
• DBMS_METADATA.SET_TRANSFORM_PARAM(
DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
• DBMS_METADATA.SET_TRANSFORM_PARAM(
DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',true);
• DBMS_METADATA.SET_TRANSFORM_PARAM(
DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES',false);
• DBMS_METADATA.SET_TRANSFORM_PARAM(
DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',false);
DBMS_METADATA con’t
• Examples of how to reverse engineer the database
• SELECT DBMS_METADATA.GET_DDL('TABLE',table_name) FROM
USER_TABLES;
• SELECT to_char(DBMS_METADATA.GET_DDL('INDEX',index_name))
FROM USER_INDEXES;
• SELECT to_char(DBMS_METADATA.GET_DEPENDENT_DDL('OBJECT_GRANT'
,table_name)) FROM USER_TABLES;
• SELECT to_char(DBMS_METADATA.GET_DEPENDENT_DDL('CONSTRAINT‘
,table_name)) FROM USER_CONSTRAINTS
where constraint_type in ('P','C');
• SELECT to_char(DBMS_METADATA.GET_DEPENDENT_DDL(
'REF_CONSTRAINT‘,table_name)) FROM USER_CONSTRAINTS
where constraint_type = 'R';
Daily Builds
Recipe:
Daily Build Database
API to Checkout Source Code
Install Scripts
Database Validation Scripts
Self Contained Unit Tests
Uninstall Scripts
Daily Builds con’t
• At times uninstall scripts may not be complete
enough to undo changes to the data
dictionary
• An alternative to uninstall scripts is using
Flashback Database
• Before running the install log the current scn
– DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER()
• When complete with all tests flashback the
database
– FLASHBACK DATABASE TO SCN ?;
Logging and Monitoring
Logging and Monitoring
CREATE TABLE EVENTLOG (
EVENTLOGID NUMBER(9) NOT NULL,
SEVERITYID NUMBER(2) DEFAULT 1 NOT NULL,
LOCATION VARCHAR2(100 BYTE) NOT NULL,
ERRORMSG VARCHAR2(4000 BYTE),
ADDITIONALINFO VARCHAR2(4000 BYTE),
CREATEDDATE DATE,
CREATEDBY NUMBER(9)
)
• http://log4plsql.sourceforge.net/
Debug Flag
• Example 1 – log info message
if (pkgeventlog.getdebugflag) then
pkgeventlog.createeventlog(1,'PkgOrderItems.AddOrderItems',
'info','Get transid',sysdate,1);
end if;
• Example 2 – log error message
EXCEPTION WHEN OTHERS THEN
vError:=substr(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE ,1,100);
pkgeventlog.createeventlog(4,'PkgOrderItems.AddOrderItems’,
'error',vError,sysdate,1);
RAISE;
Summary
• Everything can be tested
• Developers are Guilty until Proven Innocent
• Robust testing has great side effects such as:
– Reduced Rework – Spend more time developing
new code instead of fixing old code
• Agility requires confidence
• Confidence = Tests that prove the system is
correct
Resources
• forwardthinkingdb.com
– Database Architecture Resources
• agiledata.org
– Agile Database Development
Become a Complete Oracle Technology
and Database Professional
• Join the IOUG online at www.ioug.org and get immediate access
to:
– Member Discounts and Special Offers
– SELECT Journal
– Library of Oracle Knowledge (LoOK)
– Member Directory
– Special Interest Groups
– Discussion Forums:
– Access to Local and Regional Users Groups:
– 5 Minute Briefing: Oracle
– Volunteer Opportunities
Stop by the IOUG Booth
• Moscone Center West – 2nd Floor
– Register for Raffles and Giveaways
– Learn more about IOUG
– Fill out a SIG interest card
Questions/Comments?
Save the Date!
May 3-7, 2009
Orange County Convention Center West
Orlando, Florida
Tarik R. Essawi
tessawi@verisign.com
Thank You!

More Related Content

What's hot (20)

PPTX
Ten query tuning techniques every SQL Server programmer should know
Kevin Kline
 
PDF
JMeter, Docker sitting in a tree
srivaths_sankaran
 
PDF
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
PPTX
Performance testing with 100,000 concurrent users in AWS
Matthias Matook
 
PPTX
QA. Load Testing
Alex Galkin
 
PPTX
JMETER-SKILLWISE
Skillwise Consulting
 
PPTX
Load testing jmeter
Billa Kota Sriram
 
PDF
Architecting for the cloud storage build test
Len Bass
 
PPT
Performance Testing With Jmeter
Adam Goucher
 
PPT
Load Test Drupal Site Using JMeter and Amazon AWS
Vladimir Ilic
 
PDF
Learning j meter in 60 minutes
Alon Girmonsky
 
PPTX
JMeter Database Performace Testing - Keytorc Approach
Keytorc Software Testing Services
 
PPTX
Creating a Benchmarking Infrastructure That Just Works
Tim Callaghan
 
PPTX
J meter introduction
Bharath Kumar
 
PPTX
Oracle performance tuning_sfsf
Mao Geng
 
PDF
Performancetestingjmeter 131210111657-phpapp02
Nitish Bhardwaj
 
PPTX
J Meter Intro
Sam Varadarajan
 
PDF
Performance tuning in sql server
Antonios Chatzipavlis
 
PPT
Jmeter From Scratch
ChinmayBrahma22
 
PDF
Introduction to jmeter
test test
 
Ten query tuning techniques every SQL Server programmer should know
Kevin Kline
 
JMeter, Docker sitting in a tree
srivaths_sankaran
 
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Performance testing with 100,000 concurrent users in AWS
Matthias Matook
 
QA. Load Testing
Alex Galkin
 
JMETER-SKILLWISE
Skillwise Consulting
 
Load testing jmeter
Billa Kota Sriram
 
Architecting for the cloud storage build test
Len Bass
 
Performance Testing With Jmeter
Adam Goucher
 
Load Test Drupal Site Using JMeter and Amazon AWS
Vladimir Ilic
 
Learning j meter in 60 minutes
Alon Girmonsky
 
JMeter Database Performace Testing - Keytorc Approach
Keytorc Software Testing Services
 
Creating a Benchmarking Infrastructure That Just Works
Tim Callaghan
 
J meter introduction
Bharath Kumar
 
Oracle performance tuning_sfsf
Mao Geng
 
Performancetestingjmeter 131210111657-phpapp02
Nitish Bhardwaj
 
J Meter Intro
Sam Varadarajan
 
Performance tuning in sql server
Antonios Chatzipavlis
 
Jmeter From Scratch
ChinmayBrahma22
 
Introduction to jmeter
test test
 

Viewers also liked (7)

PPTX
Tiffany christensen chore chart
Tiffany Christensen
 
PPT
The Science Of Networking
Brittany Irvin
 
PPTX
Ldv tour
latterdayvillage
 
PDF
Visual Resume
hannahb31092
 
PDF
Secrets of highly_avail_oltp_archs
Tarik Essawi
 
PDF
Pak
Mohsin Amin
 
PDF
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Tiffany christensen chore chart
Tiffany Christensen
 
The Science Of Networking
Brittany Irvin
 
Visual Resume
hannahb31092
 
Secrets of highly_avail_oltp_archs
Tarik Essawi
 
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Ad

Similar to Agile db testing_techniques (20)

PPTX
utPLSQL: Unit Testing for Oracle PL/SQL
Steven Feuerstein
 
PDF
Bgoug 2019.11 test your pl sql - not your patience
Jacek Gebal
 
PDF
A data driven etl test framework sqlsat madison
Terry Bunio
 
PDF
POUG2019 - Test your PL/SQL - your database will love you
Jacek Gebal
 
PDF
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
Jacek Gebal
 
PDF
Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Jacek Gebal
 
PPTX
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
Alessandro Alpi
 
PPTX
Oracle Unit Testing with utPLSQL
Brendan Furey
 
PPT
Database continuous integration, unit test and functional test
Harry Zheng
 
PDF
Pl sql office hours data setup and teardown in database testing
DeeptiBandari
 
PPTX
Get Testing with tSQLt - SQL In The City Workshop 2014
Red Gate Software
 
PPTX
The Road to U-SQL: Experiences in Language Design (SQL Konferenz 2017 Keynote)
Michael Rys
 
PDF
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
Jacek Gebal
 
PDF
Presenter manual oracle D2K (specially for summer interns)
XPERT INFOTECH
 
PPT
SQL Police
Marcus Davage
 
DOCX
Oracle PLSQL Training in Chennai, Tambaram
Radiant Business Solutions
 
DOC
Oracle 11g sql plsql training
FuturePoint Technologies
 
PDF
Db testing concepts swt
avr07
 
PPTX
Database Unit Testing Made Easy with VSTS
Sanil Mhatre
 
PPT
A testing framework for Microsoft SQL-Server
elliando dias
 
utPLSQL: Unit Testing for Oracle PL/SQL
Steven Feuerstein
 
Bgoug 2019.11 test your pl sql - not your patience
Jacek Gebal
 
A data driven etl test framework sqlsat madison
Terry Bunio
 
POUG2019 - Test your PL/SQL - your database will love you
Jacek Gebal
 
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
Jacek Gebal
 
Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Jacek Gebal
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
Alessandro Alpi
 
Oracle Unit Testing with utPLSQL
Brendan Furey
 
Database continuous integration, unit test and functional test
Harry Zheng
 
Pl sql office hours data setup and teardown in database testing
DeeptiBandari
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Red Gate Software
 
The Road to U-SQL: Experiences in Language Design (SQL Konferenz 2017 Keynote)
Michael Rys
 
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
Jacek Gebal
 
Presenter manual oracle D2K (specially for summer interns)
XPERT INFOTECH
 
SQL Police
Marcus Davage
 
Oracle PLSQL Training in Chennai, Tambaram
Radiant Business Solutions
 
Oracle 11g sql plsql training
FuturePoint Technologies
 
Db testing concepts swt
avr07
 
Database Unit Testing Made Easy with VSTS
Sanil Mhatre
 
A testing framework for Microsoft SQL-Server
elliando dias
 
Ad

Recently uploaded (20)

PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 

Agile db testing_techniques

  • 1. Tarik R. Essawi VeriSign Inc. Agile Database Testing Techniques
  • 2. Introduction • Real world best practices • Proven Techniques • Why Test ? • How to greatly improve – PL/SQL Quality – Database Schema Installations – Reports – Build Process – Debugging and Monitoring
  • 3. Why Test ? • You will spend time testing your code. – You can manually test your code every time a change is made or a build is deployed • Manual testing is haphazard • Code coverage is sporadic at best – You can create an automated unit test once that can be run every time the code changes • Tests are repeatable • Code Coverage is repeatable
  • 4. Finding Defects • Defects will be found, the only question is when: – Options 1)You can find the defects during development 2)Quality Assurance can find the defects 3)Customers can find the defects in production
  • 5. What is Agility • A rapid change of velocity or direction in response to a stimulus • Many different forms and methods – Test Driven Development – Extreme Programming – Scrum • Foundation of Agility is Testing – Creates confidence to change direction
  • 6. Traditional QA role • Responsible for finding defects • If defects are not found in QA they are found in production
  • 7. A Different Approach • Guilty Until Proven Innocent • Developers must prove code is correct • QA role becomes: – Corroborate test results – Verify the Delivered Code meets Requirements – Focus on integration tests of corner cases
  • 8. Side Effects • Number of builds reduced • Amount of rework reduced Week0 Week1 Week2 Week3 Week4 Week5 Week6 Week7 Week8 0 5 10 15 20 25 30 35 40 Time Man Hours Development Lifecycle Automated Testing Maual Testing
  • 10. UtPlsql Installation • UtPlsql is a plsql unit testing framework. It is one of many, So if you are not using plsql other testing frameworks exist that accomplish the same goal. • Installing the package – Download zip file from • http://utplsqlsql.sourceforge.net • Unzip the file. – Create user • connect to the database as system • create user utplsql identified by utplsql default tablespace ?? temporary tablespace ??; • grant create session, create table, create procedure, create sequence, create view, create public synonym, drop public synonym to utplsql; • alter user utplsql quota unlimited on ??; • You can also just grant DBA privileges. – In the code directory where the file is unzipped, login to sqlplus as utplsql and run @ut_i_do install (you must pass in the parameter “install”). – Create public synonyms for all of the packages owned by utplsql.
  • 11. Developing the Tests • A test package is created for each application package – For example, to test PKGORDERITEMS a package called UT_ PKGORDERITEMS is created • Each package contains a ut_setup, ut_teardown, and then individual procedures to test the code • The tests are self-contained • Tests are based on assertions
  • 12. Assertions • Assertions are the heart of the testing framework • You will prove through the assertion that the results are correct • Below are the basic assertions that can satisfy 80% of test cases. – utassert.eqquery – compares multiple columns of two queries or result sets – utassert.eqqueryvalue – compares a single column returned from a query – utassert.eq –compares two values – utassert.throws – is used to test that exceptions are being thrown and caught properly • For the other 20% you can also – Compare tables, pipes, refcursors, and collections for equality – Check for null values, table counts and whether previous assertions passed or failed – You can also extend the assert procedure through inheritance and create your own
  • 13. Running Tests • Compile the test package under the same schema as the calling package • Run the test by calling utplsql.test. This is one of many ways to execute the test SET SERVEROUTPUT ON SIZE UNLIMITED BEGIN utplsql.test(package_in=>'PKGORDERITEMS', recompile_in=>FALSE); DBMS_OUTPUT.put_line (utplsql2.runnum); END;
  • 14. Running Tests Con’t • Review the output, which will say > SSSS U U CCC CCC EEEEEEE SSSS SSSS > S S U U C C C C E S S S S > S U U C C C C E S S > S U U C C E S S > SSSS U U C C EEEE SSSS SSSS > S U U C C E S S > S U U C C C C E S S > S S U U C C C C E S S S S > SSSS UUU CCC CCC EEEEEEE SSSS SSSS OR > FFFFFFF AA III L U U RRRRR EEEEEEE > F A A I L U U R R E > F A A I L U U R R E > F A A I L U U R R E > FFFF A A I L U U RRRRRR EEEE > F AAAAAAAA I L U U R R E > F A A I L U U R R E > F A A I L U U R R E > F A A III LLLLLLL UUU R R EEEEEEE .
  • 16. Install Uninstall Procedures • Install and Uninstall scripts should not require any operator input • Script should be simple and straightforward spool install.lst PROMPT Calling define_var.sql... @@define_var.sql /********************************************* * Creating Orders **********************************************/ @cr_orders.sql /********************************************* * Creating OrderItems **********************************************/ @cr_order_items_table.sql spool off; !grep 'ORA-' *.lst !grep 'SP2-' *.lst exit
  • 17. Validating Schema Installs • Schema installs are one-time tasks where quality is extremely critical • Errors during a schema install can cause an entire release to be rolled back or cause the maintenance window to be missed due to debugging • Validation scripts evolved based on the following scenarios: – Errors being written to files and never reviewed – Errors never being written to files at all – Scripts not executing, which means no error is generated – Scripts that exit part of the way through and never execute the remaining commands
  • 18. Validating Schema Installs con’t • Verify that every object that was expected to be created actually exists. • Create an assertion package that will verify the actual versus the expected. • Generate an error if the assertion fails. • Items to check – Tables – Indexes – Constraints – Synonyms and Grants – Reference data was inserted or updated as expected – Anything created during the install…
  • 19. Schema Install Validation Example • Below is an example of a database verification script. The assertion procedure was written in-house and raises an error if the first and second parameters are not equal. The verification script are tailored to each deployment. declare v_actual number; Begin -- Verify TABLE Tables select count(*) into v_actual from user_tables where table_name = ‘ORDER_ITEMS' and tablespace_name = 'DATA'; PkgValidation.assert(1, v_actual,' Verify Order Items'); -- Verify TABLE INDEXES select count(*) into v_actual from user_indexes where index_name in ('IDX_ORDER_ITEMS', 'PK_ORDER_ITEMS') and tablespace_name = 'INDEX'; PkgValidation.assert(2, v_actual,' Verify Index Creation'); -- Print Validation Summary dbms_output.put_line('======================================================='); dbms_output.put_line('**Assertions passed : '||PkgValidation.v_assertions_passed); dbms_output.put_line('**Assertions Failed : '||PkgValidation.v_assertions_failed); dbms_output.put_line('**Total Assertions : '||PkgValidation.v_total_assertions); dbms_output.put_line('======================================================='); end;
  • 20. Report Testing • Report Testing can be challenging: – Reports contain millions of rows – A single report can consist of multiple pages of SQL Code • Automating Report Testing can be accomplished: – Load the report into the database using sqlloader or external tables – Once the report is accessible within the database the source data can be compared to the report data – Assertions can be used to compare each record in the report with the source data and vice versa – This initial testing will identify common errors with complex table joins and date ranges – Controlled Datasets will validate the end to end testing of the system from the customer channel through to the reports
  • 22. Daily Build Database • The development and test environments must be functionally equivalent to production • The hardware can differ but the logical structure of the database must be an exact replica • Use the DBMS_METADATA package
  • 23. DBMS_METADATA • DBMS_METADATA.SET_TRANSFORM_PARAM( DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false); • DBMS_METADATA.SET_TRANSFORM_PARAM( DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',true); • DBMS_METADATA.SET_TRANSFORM_PARAM( DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES',false); • DBMS_METADATA.SET_TRANSFORM_PARAM( DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',false);
  • 24. DBMS_METADATA con’t • Examples of how to reverse engineer the database • SELECT DBMS_METADATA.GET_DDL('TABLE',table_name) FROM USER_TABLES; • SELECT to_char(DBMS_METADATA.GET_DDL('INDEX',index_name)) FROM USER_INDEXES; • SELECT to_char(DBMS_METADATA.GET_DEPENDENT_DDL('OBJECT_GRANT' ,table_name)) FROM USER_TABLES; • SELECT to_char(DBMS_METADATA.GET_DEPENDENT_DDL('CONSTRAINT‘ ,table_name)) FROM USER_CONSTRAINTS where constraint_type in ('P','C'); • SELECT to_char(DBMS_METADATA.GET_DEPENDENT_DDL( 'REF_CONSTRAINT‘,table_name)) FROM USER_CONSTRAINTS where constraint_type = 'R';
  • 25. Daily Builds Recipe: Daily Build Database API to Checkout Source Code Install Scripts Database Validation Scripts Self Contained Unit Tests Uninstall Scripts
  • 26. Daily Builds con’t • At times uninstall scripts may not be complete enough to undo changes to the data dictionary • An alternative to uninstall scripts is using Flashback Database • Before running the install log the current scn – DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER() • When complete with all tests flashback the database – FLASHBACK DATABASE TO SCN ?;
  • 28. Logging and Monitoring CREATE TABLE EVENTLOG ( EVENTLOGID NUMBER(9) NOT NULL, SEVERITYID NUMBER(2) DEFAULT 1 NOT NULL, LOCATION VARCHAR2(100 BYTE) NOT NULL, ERRORMSG VARCHAR2(4000 BYTE), ADDITIONALINFO VARCHAR2(4000 BYTE), CREATEDDATE DATE, CREATEDBY NUMBER(9) ) • http://log4plsql.sourceforge.net/
  • 29. Debug Flag • Example 1 – log info message if (pkgeventlog.getdebugflag) then pkgeventlog.createeventlog(1,'PkgOrderItems.AddOrderItems', 'info','Get transid',sysdate,1); end if; • Example 2 – log error message EXCEPTION WHEN OTHERS THEN vError:=substr(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE ,1,100); pkgeventlog.createeventlog(4,'PkgOrderItems.AddOrderItems’, 'error',vError,sysdate,1); RAISE;
  • 30. Summary • Everything can be tested • Developers are Guilty until Proven Innocent • Robust testing has great side effects such as: – Reduced Rework – Spend more time developing new code instead of fixing old code • Agility requires confidence • Confidence = Tests that prove the system is correct
  • 31. Resources • forwardthinkingdb.com – Database Architecture Resources • agiledata.org – Agile Database Development
  • 32. Become a Complete Oracle Technology and Database Professional • Join the IOUG online at www.ioug.org and get immediate access to: – Member Discounts and Special Offers – SELECT Journal – Library of Oracle Knowledge (LoOK) – Member Directory – Special Interest Groups – Discussion Forums: – Access to Local and Regional Users Groups: – 5 Minute Briefing: Oracle – Volunteer Opportunities
  • 33. Stop by the IOUG Booth • Moscone Center West – 2nd Floor – Register for Raffles and Giveaways – Learn more about IOUG – Fill out a SIG interest card
  • 35. Save the Date! May 3-7, 2009 Orange County Convention Center West Orlando, Florida