On Jan 11, 2008 11:33 AM, Kerry Buckley <[EMAIL PROTECTED]> wrote: > This isn't specific to RSpec, but is hopefully on-topic for this list. > > I like (especially when "ping pong pairing") to write a spec, then > write the smallest amount of code I can to pass it (especially when > "ping pong pairing"). Sometimes this means hard-coding a return value, > which means another spec is needed to prove that the code is really > behaving as it should. Trivial example: > > ---------- > describe Adder do > it "should add two numbers" do > Adder.add(2, 2).should == 4 > end > end > > class Adder > def add a, b > 4 > end > end > ---------- > describe Adder do > it "should add 2 and 2" do > Adder.add(2, 2).should == 4 > end > it "should add 3 and 4" do > Adder.add(3, 4).should == 7 > end > end > > class Adder > def add a, b > a + b > end > end > ---------- > > It doesn't seem right though to have all those duplicate specs. An > alternative is to generate random test data, but I'm not really > comfortable doing that because it means the tests aren't strictly > repeatable. I guess this is more of a problem with classic state-based > testing, but even using BDD you still have to test state at the leaf > nodes. >
It may not be applicable in your trivial context, but "pair-wise" testing (has nothing to do with pair programming) is a really powerful technique you could consider. It's a mini method that generates input combinations based on a set of possible values, dramatically reducing the number of combinations while still giving you the most important combinations. It's based on a theory that bugs often occur when a pair of data changes, and it tries to generate data that covers as many pairs as possible without going overboard. It's the most interesting test-related practice I have learned in several years (there are separate conferences on the topic!). I haven't tried it myself, but I know several colleagues who've had great success with it. There is also a tool (perl script) you can use to generate input values for you (you figure out the expected results yourself - it doesn't do that for you). And best of all - it looks really easy to use, both as a technique and a tool. http://www.testingeducation.org/wtst5/PairwisePNSQC2004.pdf http://www.pairwise.org/ http://en.wikipedia.org/wiki/All-pairs_testing http://www.developsense.com/2007/11/pairwise-testing.html http://www.developsense.com/testing/PairwiseTesting.html Aslak > Does anyone have an opinion about whether this is a problem, and > whether there's a clean way of dealing with it? > > Thanks, > > Kerry > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users