Automated Unit andIntegration Testing withNDbUnit      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 ...
Overview• Automated Integration Testing With Databases Is Really Difficult    – “Data Not In Known-State Before Test”     ...
Overview• Object Relational Mapping (ORM)    – Entity Framework    – NHibernate    – Linq2Sql• Linq Queries               ...
Overview• NDbUnit    – Database Testing Framework        • Borrows from the Java community’s DbUnit        • “.NET library...
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 Q...
Automated Integration Testing With Databases Is Really Difficult• Automated Integration Testing With Databases Is Really D...
Automated Testing The “Surface API”• “Surface Testing”    – DAL• Perhaps an example  would be helpful?                    ...
Integration Testing The ORM Interface• “Surface Testing” Revisited    – ORM Interface Surface• NDbUnit    – Independently ...
NDbUnit Downside• Independence Has A Cost   – Separately Defined The Schema   – Separately Defined Each Known-Data-State• ...
NDbUnit Upside• Liberates Refactoring    – Switch from CRUD Stored Procedures to ORM    – Database Consolidation    – Auto...
Of Course It’s Safe … After You                             Excella Consulting
Shameless Self Promotion Time!                                        Get 40% off Pro .NET Best                           ...
More Shameless Self Promotion• Email:       stephen.ritchie@excella.com• Twitter:     @ruthlesshelp• Blog:        http://r...
Upcoming SlideShare
Loading in...5
×

Automated Unit and Integration Testing with NDbUnit

4,953

Published on

Sample code available here: https://github.com/ruthlesshelp/Presentations

When coding and running automated integration tests, have you bumped into "database in an unexpected state" failures? The database is often in the wrong initial state when test code runs. NDbUnit is a .NET library for managing database state for unit and integration testing. As a database testing framework, it provides the capability to arrange the data in the database before and after a test method runs. This helps ensure that the database’s state is consistent for the execution of each test. In this presentation, you will learn:

How to unit test a stored procedure with NDbUnit
How to automate the integration testing of the data access layer
How to enable refactoring through automated integration testing
How to improve automated UI testing with NDbUnit

NDbUnit clears away some very significant automated testing obstacles, which can help you avoid common pitfalls of automated testing.

About Stephen Ritchie - Stephen Ritchie is the author of Pro .NET Best Practices (http://www.apress.com/9781430240235). He has been writing software professionally for over 20 years. He is the .NET best practices steward at Excella, working together with .NET project teams to facilitate and to implement new and better development practices. He is often called upon to setup the continuous integration server, perform code analysis, and automate the testing, packaging and deployment of software.

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
4,953
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
15
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide
  • Introductory remarks.
  • 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.
  • Automated Unit and Integration Testing with NDbUnit

    1. 1. Automated Unit andIntegration Testing withNDbUnit Stephen D. Ritchie 1-May-2012
    2. 2. Chrysler New Yorker Excella Consulting
    3. 3. Overview• Unit Testing Databases Is Difficult – CRUD Operations on Tables – Complex Querying of Multiple Tables – Views – Functions – Stored Procedures – Triggers !?! Excella Consulting
    4. 4. Overview• Automated Integration Testing With Databases Is Really Difficult – “Data Not In Known-State Before Test” Excella Consulting
    5. 5. Overview• Object Relational Mapping (ORM) – Entity Framework – NHibernate – Linq2Sql• Linq Queries Excella Consulting
    6. 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. 7. Tell Me More …• How does NDbUnit work?• Perhaps an example would be helpful … Excella Consulting
    8. 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. 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. 10. Automated Testing The “Surface API”• “Surface Testing” – DAL• Perhaps an example would be helpful? Excella Consulting
    11. 11. Integration Testing The ORM Interface• “Surface Testing” Revisited – ORM Interface Surface• NDbUnit – Independently Controls the Data Store Excella Consulting
    12. 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. 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. 14. Of Course It’s Safe … After You Excella Consulting
    15. 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. 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
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×