SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

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

Hinweis der Redaktion

  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.