TDD in PL/SQL
test driven development, software development
PL/SQL has unit testing support and tooling, but my sense is that it’s far from the world of Java or Ruby. In most modern OO languages unit testing is just a part of the landscape. TDD is evolving to BDD with tools like RSpec and modern web frameworks come with unit testing support built in from Wicket to Rails.
It’s a little different in the Oracle world. Steve Feuerstein the evangelist for TDD and unit testing in PL/SQL mentions:
utPLSQL is used by many development shops, but not nearly enough to make it a standard in the PL/SQL environment.
The difference is JUnit is a defacto standard in the Java world. Steve developed utPLSQL to allow for automated unit testing in PL/SQL and has been pushing the idea ever since.
utPLSQL is a basic xUnit framework with assertions, setup and teardown. The interface is simple with no red/green bars just a ’success’ message in ASCII art. There is a GUI front end runner called OUnit, but it hasn’t been updated in quite some time. The current leading edge unit testing tool is a commercial offering from TOAD called Quest Code Tester for Oracle.
Steve Feuerstein is the developer behind the tool. At first glance it looks like a nice option especially since we’re a TOAD shop. I’ll probably delegate it out to one of our developers to really look into it. The questions I still have are:
- Write a failing test. Write the code to make it pass. Refactor. How painful is manual refactoring in a procedural language?
- How do you hook up the test runs to a continuous integration server? And are you tied to the TOAD tool?
- How do you deal with all the actual dependencies on data in tables for tests.
- How do you avoid slow running tests?
Ed Gibbs @ May 17, 2008


Glad to read of your interest in Code Tester! We have been working hard these past two years to create a tool that offers a level of testing automation never seen before in the Oracle environment - and rarely matched even in the Java world. I offer some perspectives on your questions below.
Write a failing test. Write the code to make it pass. Refactor. How painful is manual refactoring in a procedural language?
SF - I am not sure if this is a question directed at Code Tester. Certainly, Code Tester will allow you to easily execute your test again after any changes to the program, to verify the fix.
How do you hook up the test runs to a continuous integration server? And are you tied to the TOAD tool?
SF - Code Tester is built on an Oracle backend repository, including a PL/SQL API for running tests. So as long as your CI server or script can execute a PL/SQL block, you can integrate Code Tester test execution easily into that environment. Toad offers integration points with Code Tester, but Code Tester is also a stand-alone tool that can be used side by side with any and every PL/SQL IDE.
How do you deal with all the actual dependencies on data in tables for tests.
SF - Today you still need to build your own setup scripts to insert data into tables, ensuring a consistent starting point for tests. With 1.8.1 (in final beta phase), we will also include an unsupported package that will generate these setup scripts. In the next release, this package will be supported and made available through the UI.
How do you avoid slow running tests?
SF - Generally, you should avoid copying production volumes of data into test tables. Instead, keep volume low and ensure that the tables have the VARIETY of data needed to fully exercise your logic. Also, if you use the dynamic test case generation features of Code Tester (random values, table driven testing, etc.), you simply need to watch out for generating a very large number of tests!
Hope this helps. If anyone has any other questions about Code Tester, feel free to contact me directly at steven.feuerstein@quest.com and visit our community: http://unittest.inside.quest.com/index.jspa
Warm regards, SF
TDD is not evolving into BDD; but rather, BDD is TDD as it was intended to be practiced. I would prefer people stop perpetuating this misconception that BDD and TDD are somehow different.
I agree that TDD as practiced is a far cry from TDD as described or TDD as intended, but BDD is simply TDD done well, and the more people who recognize that, the less we will confuse the community at large.
http://tinyurl.com/pgxtx
Take care.