Data Driven Testing - Part 1
It's 3am, you've been working all night on a new feature, and you're about to commit your code for QA testing; you ask yourself is this going to work?
We've all been there. No one likes their work being rejected, or being known as the developer that commits faulty code. Worse yet, the bug sneaks past the testers and is discovered months after it has been in production.
So, how do we prove our code works before we commit it into the next build? I hope you all said Unit Tests. There are many different unit testing patterns outlined at XUnit Test Patterns. This post focuses on how to maximize the test coverage of your data dependent .NET components with minimal code. Sound good? Then lets get to it.
You may be asking yourself, what is a data dependent component? In short, it is a component that takes a finite set of input values and has produces a discrete output based on those values. In the example below, we have a postal address class that has complex validation rules (region based on the country, postal/zip code based on country, etc.). I am assuming you are all familiar with NUnit; I have recently started using the MBUnit test framework as it is a lot easier to test data dependent components.
[RowTest] |
- a region that does not belong to the given country
- a postal/zip code that does not match the appropriate format for the given country
- missing data
If there are any data driven testing topics you'd like to see in a future post, please let me know.