InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Test Driven Database Development

Posted by Deborah Hartmann Preuss on Oct 04, 2006

Sections
Process & Practices,
Architecture & Design
Topics
Delivering Value ,
Customers & Requirements ,
Agile
Tags
Database ,
Refactoring ,
TDD ,
Testing
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.
  • This article is part of a featured topic series on Agile
Yes and there's more by Max Guernsey Posted
  1. Back to top

    Yes and there's more

    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

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.