SlideShare a Scribd company logo
1 of 21
Automated Unit and
Integration Testing with
Databases

      Stephen D. Ritchie
      Philly.NET Code Camp 2012.1
      12-May-2012
Chrysler New Yorker




                      Excella Consulting
Overview: Database “Units”




• Unit Testing Databases Is Difficult
    –   CRUD Operations on Tables
    –   Complex Querying of Multiple Tables
    –   Views
    –   Functions
    –   Stored Procedures
    –   Triggers !?!




                                Excella Consulting
Overview: Automated Testing Requirements




• Run Everywhere
    – Every developer must be able to run
      the combined collection of all the
      other developers’ tests.


• Continuous Integration
    – The CI server must be able to run
      the entire suite of tests without
      manual intervention.


• Deterministic, Isolated and Repeatable
    – The outcome of the tests must be unambiguous and repeatable.
      Usually, the standard is that if one test fails the entire test run fails.



                                  Excella Consulting
Overview: Databases Present Hurdles




• Automated Integration Testing with Databases

• This is Really Difficult

    – Schema Not Migrated/Versioned


    – Data Not In “Known-State”

    – Concurrency Control




                             Excella Consulting
RoundhousE




• Database Versioning and Change Management
   – Migrations Engine
   – Convention Over Configuration
• Apache License, Version 2.0
   – Free and Open Source
• NDbUnit Project
   – http://code.google.com/p/roundhouse/
• NuGet Package
   – http://nuget.org/packages/roundhouse
• Documentation
   – https://github.com/chucknorris/roundhouse/wiki




                             Excella Consulting
Tell Me More …




• How does RoundhousE work?

• Perhaps an example would be helpful …




                          Excella Consulting
Motivation




• Object Relational Mapping (ORM)
    – Entity Framework
    – NHibernate
    – Linq2Sql


• Linq Queries




                          Excella Consulting
NDbUnit




• Database Testing Framework
   – Borrows from the Java community’s DbUnit
   – “.NET library for managing database state during unit testing”
• Apache License, Version 2.0
          • Free and Open Source
• NDbUnit Project
   – http://code.google.com/p/ndbunit/
• NuGet Package
   – http://nuget.org/packages?q=NDbUnit
• Supports Many Databases
   – Microsoft SQL Server 2005 and 2008 (Express thru Enterprise)
   – Oracle (XE thru Enterprise, 9i and later)
   – SQLLite

                                   Excella Consulting
Tell Me More …




• How does NDbUnit work?

• Perhaps an example would be helpful …




                           Excella Consulting
Unit Testing Databases Is Difficult




• Unit Testing Databases Is Difficult
    –   CRUD Operations on Tables
    –   Complex Querying of Multiple Tables
    –   Views
    –   Functions
    –   Stored Procedures
    –   Triggers !?!


• Perhaps an example would be helpful …




                                Excella Consulting
Automated Integration Testing With Databases Is Really Difficult




• Automated Integration Testing With Databases Is Really Difficult
    – “Data Not In Known-State Before Test”


• Perhaps an example would be helpful …




                              Excella Consulting
Automated Testing The “Surface API”




• “Surface Testing”
    – DAL


• Perhaps an example
  would be helpful?




                            Excella Consulting
Integration Testing The ORM Interface




• “Surface Testing” Revisited
    – ORM Interface Surface


• NDbUnit
    – Independently Controls the
      Data Store




                              Excella Consulting
NDbUnit Downside




• Independence Has A Cost
   – Separately Defined The Schema
   – Separately Defined Each Known-Data-State


• Changing Schema
   – Updating DataSet
   – Updating XML Files




                            Excella Consulting
NDbUnit Upside




• Liberates Refactoring
    – Switch from CRUD Stored Procedures to ORM
    – Database Consolidation
    – Automated Integration Testing Legacy Code
        • Leap Forward
• Reporting
    – Test Report Queries Independent of Reporting Tool
• Browser Testing
    – Put Database In Known State
• Smoke, Stability, Performance, Regression and Other Testing
    – Automated Integration Testing




                              Excella Consulting
Another Option: Microsoft SQL Server




• tSQLt
    – Database Unit Testing Framework for SQL Server
    – Create & Execute Tests in
      SQL Server Management Studio
    – Free, Open Source
    – http://tsqlt.org/
• Red Gate: SQL Test
    –   Unit Test Add-In for SSMS
    –   Commercial
    –   “Powered by tSQLt” (API)
    –   http://www.red-gate.com/products/sql-development/sql-test/




                                Excella Consulting
Of Course It’s Safe … After You




                             Excella Consulting
Shameless Self Promotion Time!


                                        Get 40% off Pro .NET Best
                                        Practices!
                                        • Buy the eBook at
                                          Apress.com
                                        • Enter the promo
                                          code: PHN3T
                                        • Formats: PDF, ePub, or
                                          MOBI
                                        • Valid until May 31, 2012




                            Excella Consulting
More Shameless Self Promotion




• Code:        https://github.com/ruthlesshelp

• Slides:      http://www.slideshare.net/ruthlesshelp




                           Excella Consulting
Even More Shameless Self Promotion




• Email:       stephen.ritchie@excella.com

• Twitter:     @ruthlesshelp

• Blog:        http://ruthlesslyhelpful.net

• LinkedIn:    http://www.linkedin.com/in/sritchie

• Facebook:    http://www.facebook.com/ProDotNetBestPractices




                            Excella Consulting

More Related Content

What's hot

Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)Dmitry Sharkov
 
Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Red Gate Software
 
From Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with XtextFrom Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with XtextKarsten Thoms
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeExcella
 
LF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your DocumentationLF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your DocumentationLF_APIStrat
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Red Gate Software
 
Software requirements and estimates
Software requirements and estimatesSoftware requirements and estimates
Software requirements and estimatesChuck Reeves
 
Apache contribution-bar camp-colombo
Apache contribution-bar camp-colomboApache contribution-bar camp-colombo
Apache contribution-bar camp-colomboSagara Gunathunga
 
Clean tests
Clean testsClean tests
Clean testsAgileee
 
Finding the Bad Actor: Custom scoring & forensic name matching with Elastics...
Finding the Bad Actor: Custom scoring & forensic name matching  with Elastics...Finding the Bad Actor: Custom scoring & forensic name matching  with Elastics...
Finding the Bad Actor: Custom scoring & forensic name matching with Elastics...Charlie Hull
 
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a... [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...DevDay.org
 
COE 2017: Your first 3DEXPERIENCE customization
COE 2017: Your first 3DEXPERIENCE customizationCOE 2017: Your first 3DEXPERIENCE customization
COE 2017: Your first 3DEXPERIENCE customizationRazorleaf Corporation
 
Ideas spracklen-final
Ideas spracklen-finalIdeas spracklen-final
Ideas spracklen-finalsupportlogic
 

What's hot (17)

Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)
 
Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
From Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with XtextFrom Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with Xtext
 
Sql server infernals
Sql server infernalsSql server infernals
Sql server infernals
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
LF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your DocumentationLF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
LF_APIStrat17_Don't Repeat Yourself - Your API is Your Documentation
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 
Xtext Best Practices
Xtext Best PracticesXtext Best Practices
Xtext Best Practices
 
Software requirements and estimates
Software requirements and estimatesSoftware requirements and estimates
Software requirements and estimates
 
Apache contribution-bar camp-colombo
Apache contribution-bar camp-colomboApache contribution-bar camp-colombo
Apache contribution-bar camp-colombo
 
Unit Testing JavaScript with Jasmine
Unit Testing JavaScript with JasmineUnit Testing JavaScript with Jasmine
Unit Testing JavaScript with Jasmine
 
Clean tests
Clean testsClean tests
Clean tests
 
Finding the Bad Actor: Custom scoring & forensic name matching with Elastics...
Finding the Bad Actor: Custom scoring & forensic name matching  with Elastics...Finding the Bad Actor: Custom scoring & forensic name matching  with Elastics...
Finding the Bad Actor: Custom scoring & forensic name matching with Elastics...
 
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a... [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 
COE 2017: Your first 3DEXPERIENCE customization
COE 2017: Your first 3DEXPERIENCE customizationCOE 2017: Your first 3DEXPERIENCE customization
COE 2017: Your first 3DEXPERIENCE customization
 
Ideas spracklen-final
Ideas spracklen-finalIdeas spracklen-final
Ideas spracklen-final
 

Similar to Automated Testing with Databases

How to Build Deep Learning Models
How to Build Deep Learning ModelsHow to Build Deep Learning Models
How to Build Deep Learning ModelsJosh Patterson
 
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...garrett honeycutt
 
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 madisonTerry Bunio
 
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsRainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsJosh Carlisle
 
Agile Testing Best Practices
Agile Testing Best PracticesAgile Testing Best Practices
Agile Testing Best PracticesStephen Ritchie
 
Geek Sync | Deployment and Management of Complex Azure Environments
Geek Sync | Deployment and Management of Complex Azure EnvironmentsGeek Sync | Deployment and Management of Complex Azure Environments
Geek Sync | Deployment and Management of Complex Azure EnvironmentsIDERA Software
 
Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing
Overcoming the Obstacles, Pitfalls, and Dangers of Unit TestingOvercoming the Obstacles, Pitfalls, and Dangers of Unit Testing
Overcoming the Obstacles, Pitfalls, and Dangers of Unit TestingStephen Ritchie
 
Lightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachLightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachStephen Ritchie
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systemselliando dias
 
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangersDCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangersStephen Ritchie
 
SQL Server Clustering for Dummies
SQL Server Clustering for DummiesSQL Server Clustering for Dummies
SQL Server Clustering for DummiesMark Broadbent
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersSPC Adriatics
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Codecamp Romania
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...OpenBlend society
 
From Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@LohikaFrom Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@LohikaIvan Verhun
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your WebsiteAcquia
 

Similar to Automated Testing with Databases (20)

How to Build Deep Learning Models
How to Build Deep Learning ModelsHow to Build Deep Learning Models
How to Build Deep Learning Models
 
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...
 
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
 
Breaking data
Breaking dataBreaking data
Breaking data
 
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsRainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
 
Agile Testing Best Practices
Agile Testing Best PracticesAgile Testing Best Practices
Agile Testing Best Practices
 
Geek Sync | Deployment and Management of Complex Azure Environments
Geek Sync | Deployment and Management of Complex Azure EnvironmentsGeek Sync | Deployment and Management of Complex Azure Environments
Geek Sync | Deployment and Management of Complex Azure Environments
 
Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing
Overcoming the Obstacles, Pitfalls, and Dangers of Unit TestingOvercoming the Obstacles, Pitfalls, and Dangers of Unit Testing
Overcoming the Obstacles, Pitfalls, and Dangers of Unit Testing
 
Lightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachLightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile Approach
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systems
 
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangersDCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
DCDNUG 10/16/2012 Automated testing obstacles pitfalls dangers
 
SQL Server Clustering for Dummies
SQL Server Clustering for DummiesSQL Server Clustering for Dummies
SQL Server Clustering for Dummies
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
 
From Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@LohikaFrom Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@Lohika
 
33rd degree
33rd degree33rd degree
33rd degree
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
ow.ppt
ow.pptow.ppt
ow.ppt
 

More from Stephen Ritchie

Overview of .NET Best Practices
Overview of .NET Best PracticesOverview of .NET Best Practices
Overview of .NET Best PracticesStephen Ritchie
 
Lightweight Documentation
Lightweight DocumentationLightweight Documentation
Lightweight DocumentationStephen Ritchie
 
Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Stephen Ritchie
 
Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11Stephen Ritchie
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftStephen Ritchie
 
Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923Stephen Ritchie
 
Test Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master CraftTest Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master CraftStephen Ritchie
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftStephen Ritchie
 
Continuous Integration DCAEC12
Continuous Integration DCAEC12Continuous Integration DCAEC12
Continuous Integration DCAEC12Stephen Ritchie
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best PracticesStephen Ritchie
 
Advanced Code Analysis with .NET
Advanced Code Analysis with .NETAdvanced Code Analysis with .NET
Advanced Code Analysis with .NETStephen Ritchie
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best PracticesStephen Ritchie
 
Advanced Code Analysis In .NET
Advanced Code Analysis In .NETAdvanced Code Analysis In .NET
Advanced Code Analysis In .NETStephen Ritchie
 

More from Stephen Ritchie (14)

Overview of .NET Best Practices
Overview of .NET Best PracticesOverview of .NET Best Practices
Overview of .NET Best Practices
 
Lightweight Documentation
Lightweight DocumentationLightweight Documentation
Lightweight Documentation
 
Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015
 
DevOps Requires Agility
DevOps Requires AgilityDevOps Requires Agility
DevOps Requires Agility
 
Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11Continuous Integration - NoVA CodeCamp 2014-10-11
Continuous Integration - NoVA CodeCamp 2014-10-11
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master Craft
 
Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923Dc scrum agile_eng_20130923
Dc scrum agile_eng_20130923
 
Test Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master CraftTest Driven Development: Blueprint, Toolbox, and Master Craft
Test Driven Development: Blueprint, Toolbox, and Master Craft
 
Continuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master CraftContinuous Integration: Blueprint, Toolbox, Master Craft
Continuous Integration: Blueprint, Toolbox, Master Craft
 
Continuous Integration DCAEC12
Continuous Integration DCAEC12Continuous Integration DCAEC12
Continuous Integration DCAEC12
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best Practices
 
Advanced Code Analysis with .NET
Advanced Code Analysis with .NETAdvanced Code Analysis with .NET
Advanced Code Analysis with .NET
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best Practices
 
Advanced Code Analysis In .NET
Advanced Code Analysis In .NETAdvanced Code Analysis In .NET
Advanced Code Analysis In .NET
 

Recently uploaded

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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?Igalia
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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 Takeoffsammart93
 
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 TerraformAndrey Devyatkin
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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, Adobeapidays
 
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...Miguel Araújo
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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?
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
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...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Automated Testing with Databases

  • 1. Automated Unit and Integration Testing with Databases Stephen D. Ritchie Philly.NET Code Camp 2012.1 12-May-2012
  • 2. Chrysler New Yorker Excella Consulting
  • 3. Overview: Database “Units” • Unit Testing Databases Is Difficult – CRUD Operations on Tables – Complex Querying of Multiple Tables – Views – Functions – Stored Procedures – Triggers !?! Excella Consulting
  • 4. Overview: Automated Testing Requirements • Run Everywhere – Every developer must be able to run the combined collection of all the other developers’ tests. • Continuous Integration – The CI server must be able to run the entire suite of tests without manual intervention. • Deterministic, Isolated and Repeatable – The outcome of the tests must be unambiguous and repeatable. Usually, the standard is that if one test fails the entire test run fails. Excella Consulting
  • 5. Overview: Databases Present Hurdles • Automated Integration Testing with Databases • This is Really Difficult – Schema Not Migrated/Versioned – Data Not In “Known-State” – Concurrency Control Excella Consulting
  • 6. RoundhousE • Database Versioning and Change Management – Migrations Engine – Convention Over Configuration • Apache License, Version 2.0 – Free and Open Source • NDbUnit Project – http://code.google.com/p/roundhouse/ • NuGet Package – http://nuget.org/packages/roundhouse • Documentation – https://github.com/chucknorris/roundhouse/wiki Excella Consulting
  • 7. Tell Me More … • How does RoundhousE work? • Perhaps an example would be helpful … Excella Consulting
  • 8. Motivation • Object Relational Mapping (ORM) – Entity Framework – NHibernate – Linq2Sql • Linq Queries Excella Consulting
  • 9. NDbUnit • Database Testing Framework – Borrows from the Java community’s DbUnit – “.NET library for managing database state during unit testing” • Apache License, Version 2.0 • Free and Open Source • NDbUnit Project – http://code.google.com/p/ndbunit/ • NuGet Package – http://nuget.org/packages?q=NDbUnit • Supports Many Databases – Microsoft SQL Server 2005 and 2008 (Express thru Enterprise) – Oracle (XE thru Enterprise, 9i and later) – SQLLite Excella Consulting
  • 10. Tell Me More … • How does NDbUnit work? • Perhaps an example would be helpful … Excella Consulting
  • 11. Unit Testing Databases Is Difficult • Unit Testing Databases Is Difficult – CRUD Operations on Tables – Complex Querying of Multiple Tables – Views – Functions – Stored Procedures – Triggers !?! • Perhaps an example would be helpful … Excella Consulting
  • 12. Automated Integration Testing With Databases Is Really Difficult • Automated Integration Testing With Databases Is Really Difficult – “Data Not In Known-State Before Test” • Perhaps an example would be helpful … Excella Consulting
  • 13. Automated Testing The “Surface API” • “Surface Testing” – DAL • Perhaps an example would be helpful? Excella Consulting
  • 14. Integration Testing The ORM Interface • “Surface Testing” Revisited – ORM Interface Surface • NDbUnit – Independently Controls the Data Store Excella Consulting
  • 15. NDbUnit Downside • Independence Has A Cost – Separately Defined The Schema – Separately Defined Each Known-Data-State • Changing Schema – Updating DataSet – Updating XML Files Excella Consulting
  • 16. NDbUnit Upside • Liberates Refactoring – Switch from CRUD Stored Procedures to ORM – Database Consolidation – Automated Integration Testing Legacy Code • Leap Forward • Reporting – Test Report Queries Independent of Reporting Tool • Browser Testing – Put Database In Known State • Smoke, Stability, Performance, Regression and Other Testing – Automated Integration Testing Excella Consulting
  • 17. Another Option: Microsoft SQL Server • tSQLt – Database Unit Testing Framework for SQL Server – Create & Execute Tests in SQL Server Management Studio – Free, Open Source – http://tsqlt.org/ • Red Gate: SQL Test – Unit Test Add-In for SSMS – Commercial – “Powered by tSQLt” (API) – http://www.red-gate.com/products/sql-development/sql-test/ Excella Consulting
  • 18. Of Course It’s Safe … After You Excella Consulting
  • 19. Shameless Self Promotion Time! Get 40% off Pro .NET Best Practices! • Buy the eBook at Apress.com • Enter the promo code: PHN3T • Formats: PDF, ePub, or MOBI • Valid until May 31, 2012 Excella Consulting
  • 20. More Shameless Self Promotion • Code: https://github.com/ruthlesshelp • Slides: http://www.slideshare.net/ruthlesshelp Excella Consulting
  • 21. Even More Shameless Self Promotion • Email: stephen.ritchie@excella.com • Twitter: @ruthlesshelp • Blog: http://ruthlesslyhelpful.net • LinkedIn: http://www.linkedin.com/in/sritchie • Facebook: http://www.facebook.com/ProDotNetBestPractices Excella Consulting

Editor's Notes

  1. Introductory remarks.
  2. The database is a subsystem that is often treated like a “black box”.Development team often own the stored procedures, function, and triggers. They often have logic that satisfies an explicit or implicit requirement.In many organizations, the DBA team owns the table schema.Unit testing databases is difficult because a “unit”, such as a table, is hard to test in isolation. For example, your test code might need to use ADO.NET to query the table. Any number of configuration issues might prevent the test from passing. Besides, this is an integration test.Unit testing stored procedures is difficult because it is difficult to “Arrange” that the data in the tables is mocked so that it is in a known state before the test code executes the SP.