SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Plus de Stephen 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-11
Stephen Ritchie
 

Plus de 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
 

Dernier

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
Safe Software
 
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
 

Dernier (20)

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...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
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
 
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...
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
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
 

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

Notes de l'éditeur

  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.