SlideShare una empresa de Scribd logo
1 de 36
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!

Más contenido relacionado

La actualidad más candente

Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsf
Mao Geng
 
Performancetestingjmeter 131210111657-phpapp02
Performancetestingjmeter 131210111657-phpapp02Performancetestingjmeter 131210111657-phpapp02
Performancetestingjmeter 131210111657-phpapp02
Nitish Bhardwaj
 

La actualidad más candente (20)

Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should know
 
JMeter, Docker sitting in a tree
JMeter, Docker sitting in a treeJMeter, Docker sitting in a tree
JMeter, Docker sitting in a tree
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
 
Performance testing with 100,000 concurrent users in AWS
Performance testing with 100,000 concurrent users in AWSPerformance testing with 100,000 concurrent users in AWS
Performance testing with 100,000 concurrent users in AWS
 
QA. Load Testing
QA. Load TestingQA. Load Testing
QA. Load Testing
 
JMETER-SKILLWISE
JMETER-SKILLWISEJMETER-SKILLWISE
JMETER-SKILLWISE
 
Load testing jmeter
Load testing jmeterLoad testing jmeter
Load testing jmeter
 
Architecting for the cloud storage build test
Architecting for the cloud storage build testArchitecting for the cloud storage build test
Architecting for the cloud storage build test
 
Performance Testing With Jmeter
Performance Testing With JmeterPerformance Testing With Jmeter
Performance Testing With Jmeter
 
Load Test Drupal Site Using JMeter and Amazon AWS
Load Test Drupal Site Using JMeter and Amazon AWSLoad Test Drupal Site Using JMeter and Amazon AWS
Load Test Drupal Site Using JMeter and Amazon AWS
 
Learning j meter in 60 minutes
Learning j meter in 60 minutesLearning j meter in 60 minutes
Learning j meter in 60 minutes
 
JMeter Database Performace Testing - Keytorc Approach
JMeter Database Performace Testing - Keytorc ApproachJMeter Database Performace Testing - Keytorc Approach
JMeter Database Performace Testing - Keytorc Approach
 
Creating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just WorksCreating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just Works
 
J meter introduction
J meter introductionJ meter introduction
J meter introduction
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsf
 
Performancetestingjmeter 131210111657-phpapp02
Performancetestingjmeter 131210111657-phpapp02Performancetestingjmeter 131210111657-phpapp02
Performancetestingjmeter 131210111657-phpapp02
 
J Meter Intro
J Meter IntroJ Meter Intro
J Meter Intro
 
Performance tuning in sql server
Performance tuning in sql serverPerformance tuning in sql server
Performance tuning in sql server
 
Jmeter From Scratch
Jmeter From ScratchJmeter From Scratch
Jmeter From Scratch
 
Introduction to jmeter
Introduction to jmeterIntroduction to jmeter
Introduction to jmeter
 

Destacado (7)

Tiffany christensen chore chart
Tiffany christensen chore chartTiffany christensen chore chart
Tiffany christensen chore chart
 
The Science Of Networking
The Science Of Networking The Science Of Networking
The Science Of Networking
 
Ldv tour
Ldv tourLdv tour
Ldv tour
 
Visual Resume
Visual ResumeVisual Resume
Visual Resume
 
Secrets of highly_avail_oltp_archs
Secrets of highly_avail_oltp_archsSecrets of highly_avail_oltp_archs
Secrets of highly_avail_oltp_archs
 
Pak
PakPak
Pak
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similar a Agile db testing_techniques

A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madison
Terry Bunio
 
Test Case Management with MTM 2013
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013
Raluca Suditu
 
API-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptxAPI-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptx
amarnathdeo
 
VCS_QAPerformanceSlides
VCS_QAPerformanceSlidesVCS_QAPerformanceSlides
VCS_QAPerformanceSlides
Michael Cowan
 

Similar a Agile db testing_techniques (20)

A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madison
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Improving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific LanguageImproving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific Language
 
Breaking data
Breaking dataBreaking data
Breaking data
 
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
 
Test Case Management with MTM 2013
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013
 
Test case management with MTM 2013
Test case management with MTM 2013Test case management with MTM 2013
Test case management with MTM 2013
 
Adding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipelineAdding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipeline
 
Grant Fritchey Justin Caldicott - Best practices for database deployments
Grant Fritchey Justin Caldicott - Best practices for database deploymentsGrant Fritchey Justin Caldicott - Best practices for database deployments
Grant Fritchey Justin Caldicott - Best practices for database deployments
 
Context Driven Automation Gtac 2008
Context Driven Automation Gtac 2008Context Driven Automation Gtac 2008
Context Driven Automation Gtac 2008
 
API-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptxAPI-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptx
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQL
 
Testing Frameworks
Testing FrameworksTesting Frameworks
Testing Frameworks
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Good vs power automation frameworks
Good vs power automation frameworksGood vs power automation frameworks
Good vs power automation frameworks
 
Adding unit tests with tSQLt to the database deployment pipeline
 Adding unit tests with tSQLt to the database deployment pipeline Adding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipeline
 
VCS_QAPerformanceSlides
VCS_QAPerformanceSlidesVCS_QAPerformanceSlides
VCS_QAPerformanceSlides
 
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
 
Best Practices for Database Deployments
Best Practices for Database DeploymentsBest Practices for Database Deployments
Best Practices for Database Deployments
 
Class9_SW_Testing_Strategies.pdf
Class9_SW_Testing_Strategies.pdfClass9_SW_Testing_Strategies.pdf
Class9_SW_Testing_Strategies.pdf
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

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