Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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.

share|improve this question
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 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 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 at 10:55
    
@SamWoods: You should post that as an answer, because that's exactly the solution I'd endorse. –  vincebowdren Sep 8 at 14:46

1 Answer 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).

share|improve this answer
    
That sounds great. Is there any sample scripts that you can point me to get me started? I'll be working with postgres databases. –  mango Aug 6 at 21:49
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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