InfoQ

News

Test Driven Database Development

Posted by Deborah Hartmann on Oct 04, 2006 12:56 AM

Community
Agile
Topics
Customers & Requirements ,
Delivering Value
Tags
Testing ,
TDD ,
Database ,
Refactoring
Scott Ambler thinks it's time to start adapting well accepted code quality practices to database development.  Many organization do (or should) consider data a corporate asset: if they are implementing functionality in the database via stored procedures, stored functions, or even OO code, then shouldn't a Test Driven approach provide value there just as it does on the application server?  Ambler's experience shows the answer is "yes".

Ambler's article "Test Driven Database Development" [pdf] appears on page 4 of the September issue of TASSQuarterly magazine put out by the Toronto Association of Systems and Software Quality.  Just as developers take a Test Driven Design-based approach to developing application code, Ambler says TDD can also be applied to the database schema - he calls it TDDD.

TDD is an evolutionary approach to development which combines test-first development and refactoring. With a test-first approach to development you write a test before you write just enough production code to fulfill that test. Refactoring is a disciplined way to restructure code where you make small changes to your code to improve your design, making the code easier to understand and to modify.  Ambler does acknowledge that database refactorings are conceptually more difficult than code refactorings.

Is it possible to develop a regression test suite for the database?  What kind of tests would be written against a database schema? Ambler suggests regression tests for...
  • Scaffolding code (e.g. triggers or updateable views) which support refactorings,
  • Database methods such as stored procedures, functions, and triggers,
  • Existence of database schema elements (tables, procedures, ...)
  • View definitions,
  • Referential integrity (RI) rules,
  • Default values for a column,
  • Data invariants for a single column, and
  • Data invariants involving several columns.
He goes over the basics of TDD, and steps through a simple example. The article concludes with a list of database testing tools, including some developed by the open source software (OSS) community and a few commercial tools.

Scott W. Ambler is Practice Leader Agile Development within IBM’s Methods group. He is the author of several books, including the award winning Agile Database Techniques and the recently released Refactoring Databases: Evolutionary Database Design (Addison Wesley 2006). Further information is available on his Agile Data site.

Related Sponsor

VersionOne is recognized by Agile practitioners as the leader in Agile project management tools. Companies such as Adobe, BBC, CNN, Dow, HP, IBM, Sony and 3M have turned to VersionOne to help deliver greater value to their customers.
Yes and there's more by Max Guernsey Posted Mar 11, 2008 9:42 AM
  1. Back to top

    Yes and there's more

    Mar 11, 2008 9:42 AM by Max Guernsey

    I agree with all of that. Everything that Scott is saying we need is absolutely necessary. ...and there's more, too. We have to go beyond just applying the practices we've developed for software and build new practices tailored to the needs of databases. I'm writing a series of articles expanding on what we know about agility to try and make it fit into the database world.

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.