couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <B.Cand...@pobox.com>
Subject Re: Tests/TDD for CouchDB views
Date Sat, 07 Nov 2009 21:58:41 GMT
On Sat, Nov 07, 2009 at 02:31:04PM +0100, Karel Minařík wrote:
> So, my questions are basically these:
>
> * How do would you write/implement tests for your views?

I don't see in principle why it can't be any different to normal tests. That
is, you write tests within your application testing framework which:
- setup a database and some sample data
- perform a view query
- check the results are what you expect

> * What is the recommended practice for writing the views? In Futon? In  
> an editor and uploading them to db via couchapp or similar? Via  
> CouchRest or similar layer?

I do the latter (using my own CouchTiny rather than CouchRest). Your views
are source-controlled together with the rest of your application, your
application can populate the design docs when required, and you can
integrate your view tests with your application tests just as you wish.

> * Is it possible to write views "test-first|driven", ie. setting up some 
> fixtures, writing the view, etc? Does it even make sense in CouchDB 
> context?

I think so, if the test is part of your application (e.g. your application
is in Ruby and you're using something like CouchRest to manage your design
docs). View tests are just exercising another part of your app.

> * Is there a way to automatically run such test suites? (Via browser, or 
> something like Rhino?)

Same.

> * Regarding application logic itself, what would be the best/preferred  
> way to test CouchDB-backed models in eg. Rails app? Using eg. FakeWeb  
> [4] to mock responses and work with those? Or setting up and using  
> another CouchDB database (like Rails does for *SQL dbs)?

You can set up 'test', 'development' and 'production' environments for
CouchDB just as ActiveRecord does, and this is how I handle it. See
http://github.com/candlerb/couchtiny/blob/master/doc/RAILS.rdoc

Note: this is for my own CouchTiny, which is subject to change at my
personal whim so I wouldn't recommend anyone to depend on it right now, but
you should be able to apply the same approach to CouchRest.

Regards,

Brian.

Mime
View raw message