Many times in the past I have created tests for applications that use a complex database structure to produce some results. Every time I have resorted to setting up a static data structure and then make my tests agains that collection of data.
The problem with my old approach is that it is not very stable. What if someone tampers with your data? What if you want to move the tests to a UAT environment, or worse yet - production?
The ideal scenario, I think, is to have the test
1. Set all the necessary data up
2. Do the test
3. Clean up the data
But that sounds a lot simpler than it is.
Setting the data up
Using Soap UI I created a bunch of JDBC test steps to create every tiny bit of data that I needed. I put all of these steps in a disabled test case that I trigger manually from the actual cases.
I divided the data into two categories
- Stable data, or "master data"
This data will most probably exist in all environments, but not necessarily with the same ids.
Therefore a needed a bunch of "find XXX" test steps. I then transferred all those values into properties I could access later.
- Dynamic data
This is the data I will perform my actual tests against. Its important that I have full control over this data to create valid tests and to be able to trust the results. For this I created a bunch of JDBC steps that insert data into different tables.