SlideShare a Scribd company logo
1 of 16
Automated Unit and
Integration Testing with
NDbUnit

      Stephen D. Ritchie
      1-May-2012
Chrysler New Yorker




                      Excella Consulting
Overview




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




                                Excella Consulting
Overview




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




                              Excella Consulting
Overview




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


• Linq Queries




                          Excella Consulting
Overview




• 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
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: CMAP12
                                        • Formats: PDF, ePub, or
                                          MOBI
                                        • Valid until May 31, 2012




                            Excella Consulting
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

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
 
Lightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachLightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachStephen 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
 
Agile Testing Best Practices
Agile Testing Best PracticesAgile Testing Best Practices
Agile Testing Best PracticesStephen Ritchie
 
Continuous Integration DCAEC12
Continuous Integration DCAEC12Continuous Integration DCAEC12
Continuous Integration DCAEC12Stephen Ritchie
 
Advanced Code Analysis with .NET
Advanced Code Analysis with .NETAdvanced Code Analysis with .NET
Advanced Code Analysis with .NETStephen Ritchie
 
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
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best PracticesStephen 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
 
Lightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile ApproachLightweight Documentation: An Agile Approach
Lightweight Documentation: An Agile Approach
 
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
 
Agile Testing Best Practices
Agile Testing Best PracticesAgile Testing Best Practices
Agile Testing Best Practices
 
Continuous Integration DCAEC12
Continuous Integration DCAEC12Continuous Integration DCAEC12
Continuous Integration DCAEC12
 
Advanced Code Analysis with .NET
Advanced Code Analysis with .NETAdvanced Code Analysis with .NET
Advanced Code Analysis with .NET
 
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
 
An Overview of .NET Best Practices
An Overview of .NET Best PracticesAn Overview of .NET Best Practices
An Overview of .NET Best Practices
 

Recently uploaded

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 WoodJuan lago vázquez
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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...Drew Madelung
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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 FresherRemote DBA Services
 
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
 
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 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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 businesspanagenda
 

Recently uploaded (20)

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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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?
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 

Automated Unit and Integration Testing with NDbUnit

  • 1. Automated Unit and Integration Testing with NDbUnit Stephen D. Ritchie 1-May-2012
  • 2. Chrysler New Yorker Excella Consulting
  • 3. Overview • Unit Testing Databases Is Difficult – CRUD Operations on Tables – Complex Querying of Multiple Tables – Views – Functions – Stored Procedures – Triggers !?! Excella Consulting
  • 4. Overview • Automated Integration Testing With Databases Is Really Difficult – “Data Not In Known-State Before Test” Excella Consulting
  • 5. Overview • Object Relational Mapping (ORM) – Entity Framework – NHibernate – Linq2Sql • Linq Queries Excella Consulting
  • 6. Overview • 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
  • 7. Tell Me More … • How does NDbUnit work? • Perhaps an example would be helpful … Excella Consulting
  • 8. 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
  • 9. 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
  • 10. Automated Testing The “Surface API” • “Surface Testing” – DAL • Perhaps an example would be helpful? Excella Consulting
  • 11. Integration Testing The ORM Interface • “Surface Testing” Revisited – ORM Interface Surface • NDbUnit – Independently Controls the Data Store Excella Consulting
  • 12. 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
  • 13. 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
  • 14. Of Course It’s Safe … After You Excella Consulting
  • 15. Shameless Self Promotion Time! Get 40% off Pro .NET Best Practices! • Buy the eBook at Apress.com • Enter the promo code: CMAP12 • Formats: PDF, ePub, or MOBI • Valid until May 31, 2012 Excella Consulting
  • 16. 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.