天天看点

[FitNesse|cucumber]FitNesse与cucumber行为驱动测试开发的典范

i was recently tasked with piloting a couple of design tools designed to help us with our development. 

the first one was fitnesse, and the second cucumber with groovy. 

the problem with “cutting edge” pieces of software tooling is that the tutorials are often up to the mercy of those who pioneered it. this is not always a good thing. in fact unless they are communicative experts its a bad thing; its a bad thing because the guys who come up with this magnificent software aren’t always the same as the guys who are able to write the best tutorials, and explain the simplest concepts (or see the need to). 

quote: 

“fitnesse is a software development collaboration tool 

great software requires collaboration and communication. fitnesse is a tool for enhancing collaboration in software development. 

fitnesse enables customers, testers, and programmers to learn what their software should do, and to automatically compare that to what it actually does do. it compares customers’ expectations to actual results. 

it’s an invaluable way to collaborate on complicated problems (and get them right) early in development” 

well righto! thats right and its also correct, so what is it? 

well its this diagram and this is the truth: 

so what is it? (those who remember cat in red dwarf a cult tv comedy classic ) 

in one sentence: 

its a wiki, that enables a ba to put in expected outputs given inputs, which plugs into an easily codable java adaptor designed to plug the values into your system. (ah why didn’t you say so) 

what do you need? 

developers willing to code adaptor classes that populate your business objects/services using setters and getters. 

ba’s willing to use the wiki, and learn its own little language syntax. 

setup 

overall it was quite straightforwards to setup, i found the options were not amazingly intuitive but after a while i got the hang of it, and its nice to see the green filling in the boxes to show your adaptor (fixture) class is discovered and tests passed. 

what is cucumber and groovy? 

well seems a little simpler from the outset but it has no wiki. the idea is: 

1: describe behaviour in plain text 

2: write a step definition in ruby 

3: run and watch it fail 

4. write code to make the step pass 

5. run again and see the step pass 

6. repeat 2-5 until green like a cuke 

7. repeat 1-6 until the money runs out 

ah looks good except for the ruby bit because i have groovy, and that took long enough to get working. good news comes in the form of cuke4duke which gets cucumber to work with groovy. 

fortunately the guy who did it had some examples underneath the tutorial (aslak hellesoy) and i was eventually able to piece together some command line prompt uses from elsewhere on the net. 

so what is cucumber and groovy in my words? 

cucumber involves a form of structured english language in the form of a scenario or set of scenarios. 

eg: 

feature: bmi calculator feature 

in order to ensure that my bmi calculator 

as a moderately overweight developer 

i want to run a cucumber test find out if it works or sucks 

scenario: robert thorough 

given i have entered robert as a name 

and i have entered 5 in feet 

and i have entered 9 in inches 

and i have entered 190 in pounds 

when i call calculatebmiservice 

then the stored result should be 28.1 

and the stones should be 13 stones 

groovy then receives these instructions and using regex sneakily uses the jvm (without compilation need) to test the assertions. 

eg. 

before() { 

input = new com.rob.calculators.bmicalculatorinput(); 

output = new com.rob.calculators.bmicalculatoroutput(); 

bmicalculator = new com.rob.calculators.bmicalculator(); 

given(~"i have entered (.*) as a name") { string name -> 

input.setname(name) 

i found it a little trickier and slightly frustrating to setup in terms of command line stuff, but i eventually got there, configuration is the bane of me so this is where i am most likely to get frustrated and give up, but after i got there it seemed to behave itself! 

and thats it. 

what do i prefer? hmm junit, maybe thats because i am willing to sit with a ba/tester/person and write the unit tests so theres a bit of affinity bias there 

i actually like them both, but i would say that cucumber may edge it, for the domain language used will help slightly more in delivering business value, but i would expect both of these to evolve over the coming months and couple of years to something where both are better than either of them now. the only thing that put me off about the domain language of fitnesse was the use of “fixtures”, quite obvious when you know but not when you don’t, remember its about selling this to those who are new to the product. if they had said the slightly more wordy “custom static adaptor” then as a java guy i’d know about it, and as it in my case is written in java then thats the right domain terminology. they could have written “custom glue code”, and i’d have had a better idea too, the name itself made me think that its another domain specific language with nuances i need to learn. 

these are great great tools, made by extremely intelligent people (far more than myself) but often they dont have the time to sell it / package it / sugar coat it into something that will be found easy by all those invovled in using it, and by that i am talking business and ba’s. 

its one thing creating an expert tool/concept/idea, but if you can explain with examples in a really simple manner then it makes the job easier for people who come across the tool (who may not have fantastic communication/selling skills) who want to adopt agile and are also trying to sell to their bosses so they can get top down buy in. 

in balance now i know them a little more i’d be comfortable with using them both, in fact i would try them both rather than reccomend one of them, each project team has a slightly different domain, and remember we are into writing really good software, whatever tool works best we use. if the company is “wiki-mad” and the requirements are less wordy and more calculative and the java developers very enthusiastic then there is no reason fitnesse wont work well. if you already use groovy it may be a mistake to go towards fitnesse, but still try both and see! experiment! 

转载别人的文章注明了出处:http://blog.agile78.co.uk/?p=171