Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 14523 invoked from network); 10 Nov 2009 20:24:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Nov 2009 20:24:23 -0000 Received: (qmail 11311 invoked by uid 500); 10 Nov 2009 20:24:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 11253 invoked by uid 500); 10 Nov 2009 20:24:21 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 11243 invoked by uid 99); 10 Nov 2009 20:24:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Nov 2009 20:24:21 +0000 X-ASF-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of b.candler@pobox.com designates 64.74.157.62 as permitted sender) Received: from [64.74.157.62] (HELO sasl.smtp.pobox.com) (64.74.157.62) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Nov 2009 20:24:19 +0000 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 182B19AB21; Tue, 10 Nov 2009 15:23:58 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:message-id:references:mime-version:content-type :in-reply-to:content-transfer-encoding; s=sasl; bh=ym6hBeZtk25HJ Iub3qIPrrS2HMQ=; b=wURu19NzmNPv8JB1wyzTA7jlgOjeoZC4sq7kFxvIZoB8W 7OSP1Si/Nikubw/Fh8QfJ0GaDmq0tNBltmWz90/hgiRltEiKJaPFmOtaAh2YCxHm ebUab11uAje+N1U94+MLNpFy7IRPHbfBImLT31veXKWKkTJomChJuhCCnXAGpc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=date:from:to:cc :subject:message-id:references:mime-version:content-type :in-reply-to:content-transfer-encoding; q=dns; s=sasl; b=fRkYUde twaVg5kuFiEj1oU3SZn2hk83Y5OZlVvPDOuO9kE2KFIKw/vNyxt2gYWZDC+jd8F+ MAqnvVYXnVPbLEicIQo4s6yQLyzFqauT+TWtrPkGDZKQyLckwmSka1EJ+CkLpX/x n/bZpkKljn5zAQvOUkdg8lxmeC9APKKLHmOQ= Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 076CD9AB20; Tue, 10 Nov 2009 15:23:57 -0500 (EST) Received: from mappit (unknown [80.45.95.114]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 1B1A89AB1F; Tue, 10 Nov 2009 15:23:54 -0500 (EST) Received: from brian by mappit with local (Exim 4.69) (envelope-from ) id 1N7xFo-000574-2q; Tue, 10 Nov 2009 20:23:52 +0000 Date: Tue, 10 Nov 2009 20:23:51 +0000 From: Brian Candler To: Karel =?utf-8?B?TWluYcWZw61r?= Cc: user@couchdb.apache.org Subject: Re: Tests/TDD for CouchDB views Message-ID: <20091110202351.GC18411@uk.tiscali.com> Mail-Followup-To: Karel =?utf-8?B?TWluYcWZw61r?= , user@couchdb.apache.org References: <5B348DFD-D44B-48F2-8438-2F5FD63F9317@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5B348DFD-D44B-48F2-8438-2F5FD63F9317@gmail.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Pobox-Relay-ID: F910A4C6-CE36-11DE-8336-BD45BBB5EC2E-28021239!a-pb-sasl-sd.pobox.com Content-Transfer-Encoding: quoted-printable On Tue, Nov 10, 2009 at 11:44:27AM +0100, Karel Mina=C5=99=C3=ADk wrote: >>> * 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 =20 >> tests. That >> is, you ... > > of course, it is not different *in principle* at all. I am specifically= =20 > curious about concrete strategies/techniques/best practices or ways *ho= w*=20 > to do it. Eg., Jan has a fixture directly in the design document: how=20 > does one work with it then? Is this a good way to TDD views? I tend to steer away from static fixtures, but populate the DB directly within tests. Digging through some code, I note I have a complex view and unit tests exactly as you're describing. The tests look like this: class FooTest < Test::Unit::TestCase context "bar_view" do setup do @db =3D DB('test') @db.recreate_database! @foos =3D Foo.on(@db) @foos.create!(...) @foos.create!(...) @foos.create!(...) @foos.create!(...) end should "reduce across range" do res =3D @foos.view "by_bar", :reduce=3D>true, :startkey=3D>..., :endkey=3D>... assert_equal [{ "key"=3D>nil, "value"=3D>{ "count"=3D>2, "min_flurble"=3D>..., "max_flurble"=3D>..., } }], res end end So this test is basically the same as a typical functional test: - put the database into a known state - do something (query the view) - check the result It certainly could be interesting to test at a more "unit" level. You cou= ld fire up the js view server, stuff some documents into it, and check the values emitted. But I think it would get fairly icky testing reduce and re-reduce functions this way. (OTOH, it's not always easy to set up suita= ble data to exercise re-reduce properly, or be sure you've covered them prope= rly) > So I am not convinced that tying the view tests/development/generation = =20 > to the app is neccessarily the best way. If you want to deploy your views separately to any "app" using them, then= I agree with you that it makes sense to test them separately. Perhaps Couch= App could have a little framework for this. There are much more than views which you might want to test of course - e= .g. validate_doc_update functions, _show and _list. Regards, Brian.