1

I'm a bit new to mocking data for testing. I'm using ruby in conjunction with watir-webdriver and I have a local version of the app. I'd like to run a script which empties the tables of the local database, and then preloads with defined values so that the browser integration suite can run and check for expected values. The problem is that I have no idea how to start.

I think i will use a pg gem. But I'd like the data to be the same every test run, so I'd rather not have a data generator, so It looks like scripts are the way to go, but I have no idea what the best practices are around this or what it should look like.

4
  • 1
    If it should be exactly the same, could you back up the database and simply restore it before the automated run? That might be simpler than executing a bunch of updates programatically.
    – Sam Woods
    Aug 5, 2014 at 0:18
  • I suppose you're right. I could just package database copies that I'd like for testing. Are there any editors for databases that I could use for initial edits though?
    – mango
    Aug 5, 2014 at 3:29
  • It would depend on which database flavor you're using - generally something like this is one you base off the production database and modify to suit your needs, then your automation includes restoring the backup of that database into your local system. I know this can be done by a command line with MS SQL, and I'm pretty sure command line will work for all the other major database servers.
    – Kate Paulk
    Aug 5, 2014 at 10:55
  • @SamWoods: You should post that as an answer, because that's exactly the solution I'd endorse. Sep 8, 2014 at 14:46

1 Answer 1

1

In Linux you could write a bash shell script to load a database so you are at a known place for your testing. In windows you could use PowerShell to do it quite easily for MS SQL. There should be automation options for all the mature databases. As you don't specify your OS or database more specific help is unlikely.

A sane thing you might consider doing depending on how you deploy your app is to write a set of scripts to create the database schema and then populate it with your expected initial data, following that you would run the script to populate the extra data that you need for test. This tests your generation of your database (if you need this sort of testing).

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.