Alex Rivera | Logout

How do you add sample (dummy) data to your unit tests?

Asked 2009-07-08T11:37:34.800
11

In bigger projects my unit tests usually require some "dummy" (sample) data to run with. Some default customers, users, etc. I was wondering how your setup looks like.

  1. How do you organize/maintain this data?
  2. How do you apply it to your unit tests (any automation tool)?
  3. Do you actually require test data or do you think it's useless?

My current solution:

I differentiate between Master data and Sample data where the former will be available when the system goes into production (installed for the first time) and the latter are typical use cases I require for my tests to run (and to play during development).

I store all this in an Excel file (because it's so damn easy to maintain) where each worksheet contains a specific entity (e.g. users, customers, etc.) and is flagged either master or sample.

I have 2 test cases which I (miss)use to import the necessary data:

  1. InitForDevelopment (Create Schema, Import Master data, Import Sample data)
  2. InitForProduction (Create Schema, Import Master data)
Edit
Report

1 Answer

1

In our company we discuss exact these problem a bunch of time since weeks and month.

To follow the guideline of unit testing:

Each test must be atomar and don't allow relate to each other (No data sharing), that means, each tust must be have there own data at the beginning and clear the data at end.

Out product is so complex (5 years development, over 100 tables in a database), that is nearly impossible to maintain this in a acceptable way.

We tried out database scripts, which creates and deletes the data before / after the test (there are automatic methods which call it).

I would say you are on a good way with excel files.

Ideas from me to make it a little well:

  • If you have a database behind your software google for "NDBUnit". It's a framework to insert and delete data in databases for unit tests.
  • If you have no database maybe XML is a little more flexible on systems like excel.
answered 2009-07-08T11:46:12.270

Your Answer