automated testing against a persistent store with state

0 views
Skip to first unread message

Larry Siden

unread,
Jan 28, 2010, 6:14:07 PM1/28/10
to rubyd...@googlegroups.com, a2...@googlegroups.com
I want to use Rspec to test a web service with a database back-end that I am writing.  So I want to run tests like:

1) When I do POST http://.../accounts { ...JSON account parameters ...}
I get back HTTP header Location: /accounts/<new account id>

2) Then, when I do GET http://.../accounts<new account id>
I get back HTTP response { ... JSON account parameters ... } that match what I posted in the first step.

more steps ...

So the steps are sequenced and contain implicit dependencies on previous steps.  

My problem is that test libraries like Test::Unit, Rspec, and Cucumber typically apply the caveat that tests are independent and do not depend on previous tests.  

One work-around might be to put all the dependent steps into the same test where they can be reliably sequenced, and results of one step can be used as a parameter to the next (the account id in the previous example).

But after I create an account, there are many more things I need to test on this account, so putting all the steps into one test would result in one very large scenario (if done in Cucumber, or "it does ..." if defined in Rspec).

Surely, I can't be the first programmer (using Ruby or other language) to have been faced with this problem.  Is there a best practice for doing automated testing against a database (or any store) where state is persisted?  

Please don't suggest mock objects.  Mock objects can't tell me if my queries/statements will work on a real database.

Any help would be appreciated.

Larry Siden, 734-926-9614, http://umich.edu/~lsiden

The United States is a nation of laws, badly written and randomly enforced.
--Frank Zappa 1940-1993
Reply all
Reply to author
Forward
0 new messages