Behavior Driven Database Development

12 October 2009
When Behavior Driven Development (BDD) was introduced, some of the key principles were * Requirements are behavior, * Provides "ubiquitous language" for analysis, * Acceptance criteria should be executable. * Design constraints should be made into executable tests.

When Behavior Driven Development (BDD) [1] was introduced, some of the key principles were

* Requirements are behavior,
* Provides "ubiquitous language" for analysis,
* Acceptance criteria should be executable.
* Design constraints should be made into executable tests.

All of these principles can be applied to database development. When interacting with the database, we tend to assume certain behavior of the database. Some of this is universal, like when a row is inserted in a table, the same row can later be retrieved. There are other behaviors of the database on every project that are not that universal, like Person table should have at least firstname or lastname. This behavior changes based on the functionality being developed and thus needs to be properly specified and executed. The database lends itself very well to the new way of thinking in the BDD space, where the behavior of the objects is considered. BDD is similar to describing requirements in code.

I am going show how the BDD technique can be applied to database development and how this technique can be used to develop and design databases in an iterative and incremental way.

While designing database objects, we are expecting these objects to behave in a certain fashion and we tend to rely on this behavior. Let's say we make a column NOT NULLABLE. We assume that the database server will throw an exception when a NULL value in inserted in this column. Making the column NULLABLE can alter this behavior of the database. When the behavior of the database is changed this way, all the assumptions that the application made about the database NOT allowing NULL values in the column are no longer true. To avoid these kinds of mistake, we can test the database behavior to assert that the database does throw an exception when NULL values are put in column. In this article I will talk about

* Design a Table
* Design a Primary Key
* Design a Not Null Column
* Design a Constraint on a Column
* Design a Foreign Key Constraint
* Design a Sequence for Object ID
* Design a Unique Index

 

blog comments powered by Disqus