TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Case Against Cucumber

113 pointsby gigasquidover 11 years ago

33 comments

andrewvcover 11 years ago
I&#x27;ve been working in Rails since 1.2, and the vast majority of developers I&#x27;ve met have been of the opinion that cucumber sucks. There&#x27;s a <i>really</i> vocal minority on the internet though, so you&#x27;d get the impression that it&#x27;s pretty popular.<p>That said, almost every rails project I&#x27;ve worked on has had the cucumber gem included at some point, just not actively used.<p>IMHO the <i>vocal</i> Rails community puts too much emphasis on testing. I write tests for my code, but not as many as some would like. The RSpec book in particular is a gigantic load of crap. And I say this as a fan of comprehensive tests! The ridiculous lengths that book goes through in testing that codebreaker game are so detached from reality it makes my head hurt.
评论 #6412391 未加载
评论 #6412424 未加载
评论 #6412250 未加载
评论 #6412696 未加载
评论 #6412722 未加载
评论 #6412189 未加载
评论 #6412229 未加载
评论 #6412754 未加载
stephenover 11 years ago
My impression (as a static typing bigot) is that Cucumber style testing is like the crap shoot of dynamic testing (what should I type? What are valid commands? What params do they accept?) made an order of magnitude worse by using regular expressions.<p>...who thought this was a good idea? (Sorry, being harsh.)<p>That said, I think the <i>idea</i> is conceptually fine, and, as usual, I think could actually be fairly pleasant with the right (static) tooling applied, e.g. ThoughtWorks&#x27;s Twist:<p><a href="http://www.thoughtworks.com/products/twist-agile-testing/" rel="nofollow">http:&#x2F;&#x2F;www.thoughtworks.com&#x2F;products&#x2F;twist-agile-testing&#x2F;</a><p>Which is a GUI that provides all the nicities of &quot;what commands are allowed&quot;, &quot;what params do they take&quot;, &quot;oh, refactor this command name from abc to xyz&quot;, etc.<p>I think PM&#x2F;testing types would love this sort of setup. Granted, it would still take dev investment to get the fixtures&#x2F;commands&#x2F;etc. setup. But if you have a huge line-of-business app that will drive a business for the next 5-10 years, I think that&#x27;s a good investment.<p>Disclaimer: I&#x27;ve never actually used Twist because it&#x27;s a commercial product. Yes, I know I suck.
评论 #6412558 未加载
评论 #6412607 未加载
darkchasmaover 11 years ago
Cucumber has been a great success for our team. We&#x27;ve trained the BA&#x27;s how to write cucumber scripts, which in turn has done a lot to train the BA&#x27;s in how to think about the stories and features that they are requesting. The dev will sit down with this feature definition and the BA&#x27;s, and the feature is groomed into a viable and feasible feature that is testable. We strap these to a web automation (we use specflow to watin), and get a fairly significant return on investment.<p>Cucumber is like any tool; if used correctly, it&#x27;s great, and if it&#x27;s used as a de facto tool, then you&#x27;re going to struggle with it.
projectileboyover 11 years ago
For the most part, in my experience Cucumber isn&#x27;t worth the effort (one place called it &quot;Encumber&quot;). If you have product managers or BAs who can read code, then it&#x27;s easier to capture the requirements with more developer-friendly testing tools. And if the product managers or BAs do not read code, Cucumber doesn&#x27;t usually help much.<p>Having said that, I did work a gig where the tester would sit with the subject matter experts, and as they would talk, he would capture what they were saying as Cucumber tests, and he would then echo the tests back to them to see if they were right. Afterwards, he would then add whatever other tests he needed (checking weird edge cases and such), and code up any additional fixtures he needed. Then it was just a matter of me getting all the tests to pass. It was a really nice way to work - I knew unambiguously when I was done with something. (It helped that the tester sat right next to me.)
ollysbover 11 years ago
I&#x27;m a huge fan of the gherkin format, it let&#x27;s me sketch out a feature and then work through it methodically, testing as I go. But cucumber has a critical flaw, it forces you to think about code while you&#x27;re writing. Because step definitions are global you can&#x27;t just write any old thing, you might fire off a step you wrote previously. This is only a side issue though, compared to the biggest problem, step reuse.<p><pre><code> Given a person &quot;fred&quot; exists And a person &quot;ethel&quot; exists And a fatherhood exists with parent: person &quot;fred&quot;, child: person &quot;ethel&quot; </code></pre> Did someone mention cucumber steps are written in english? What happened to:<p><pre><code> Given Ethel has a father called Fred </code></pre> I moved over to Spinach[1] about 18 months ago and I&#x27;ve been much happier. Steps are specific to a feature so I can go to town with shakespearean english. Reuse isn&#x27;t an issue either, it just happens in the step definitions, not in the gherkin files. Using more natural english tends to lead to fewer larger steps anyway, so it feels a lot less like call-by-regex.<p>[1] <a href="https://github.com/codegram/spinach" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;codegram&#x2F;spinach</a>
评论 #6412542 未加载
karmajunkieover 11 years ago
TL;DR stop bitching about an acceptance testing tool when you&#x27;re not using for acceptance testing.<p>The problem isn&#x27;t with Cucumber. The problem is your cukes suck. This is probably also a problem in your Rspec&#x2F;Minitest&#x2F;whatever tests. If you&#x27;re using cucumber the way 90% of the cucumber tests I&#x27;ve ever seen (indeed, a great many i&#x27;ve written myself) are written, then you&#x27;re writing integration tests, and probably crappy ones at that.<p><pre><code> Given a user And I go to some really cool page And I click on some button </code></pre> is NOT a domain test. Domains, for the most part, don&#x27;t have &#x27;users&#x27; (unless maybe your domain is drug addiction). Or &#x27;pages&#x27; (unless you&#x27;re in publishing). And they&#x27;re definitely not about &#x27;buttons&#x27; (unless you&#x27;re a tailor.) [Yeah, you can probably find some domains where those are actual concepts. They&#x27;re probably not all concepts in the same domain.]<p>Write actual domain tests for your acceptance tests. Do this regardless of your framework—there&#x27;s absolutely nothing preventing you from doing it rspec or anything else. Fuck step reuse (gherkin alternatives like spinach are great, specifically because the steps are isolated to the test.)<p>If you don&#x27;t want to write acceptance tests, and you feel comfortable with that, no biggie. Lots of people don&#x27;t. But don&#x27;t create a straw man out of Cucumber just because you don&#x27;t understand layers of testing.<p>This goes for Cucumber fanboys as well. Don&#x27;t push cucumber into layers it doesn&#x27;t belong. Its a <i>domain</i> testing tool. Not an integration test. definitely not a unit test. Don&#x27;t push it on a team that doesn&#x27;t want it. You can write the same kinds of tests in rspec. Disclaimer: I like cucumber. I am not using it in my current job because it wasn&#x27;t a good fit for the company. I will probably use it again one day. I still write AT&#x27;s.<p>This:<p><pre><code> Given I hate cucumber And I post a scree against it Then the haters will rejoice </code></pre> is pretty much the same as this:<p><pre><code> describe &quot;hating on cucumber&quot; do it &quot;produces a response&quot; do given_i_hate_cucumber when_i_post_a_scree then_haters_rejoice end def given_i_hate_cucumber end #.... end</code></pre>
评论 #6412622 未加载
评论 #6412610 未加载
评论 #6412578 未加载
评论 #6413508 未加载
评论 #6412524 未加载
etagwerkerover 11 years ago
I&#x27;ve been using Cucumber for almost 3 years now, but if I were to start a new project today I&#x27;d pick Capybara with MiniTest or RSpec.<p>When I first started using Cucumber I thought it was cool that &quot;anyone could read the test and understand it&quot;<p>But that one advantage doesn&#x27;t really matter that much when everybody in your project knows Ruby and doesn&#x27;t need the natural language side of it.
评论 #6412673 未加载
评论 #6412467 未加载
bsnapeover 11 years ago
I think you&#x27;re perhaps missing the point in one or two places.<p>Cucumber helps techies (devs, testers, etc.) and non-techies (product owners, scrum masters etc.) work collaboratively. I don&#x27;t think the authors of Cucumber ever said that it enables non-technical people to &#x27;read and understand the underlying code&#x27;.<p>Ultimately though, I agree with your conclusion but for slightly different reasons. I use both RSpec and Cucumber daily; they are both awesome and provide a similar end result. I enjoy writing Cucumber features but in certain circumstances it doesn&#x27;t scale for large&#x2F;complex applications (in my experience). I think that this isn&#x27;t a problem for many people though, unless they&#x27;re doing something wrong &#x27;under the hood&#x27;.
huntedsnarkover 11 years ago
I couldn&#x27;t agree more. The pipe dream is that you have BAs or other non-technical team members write the Gherkin specs and that saves the developers time because &quot;the tests practically write themselves!&quot; (Assuming you&#x27;re maintaing your giant library of awkward cucumber regex matchers...). In reality it takes much longer to sit down with someone and teach them how to write in Gherkin, all for the goal of having a human readable spec that doubles as test steps. It&#x27;s much better if they write the specs however they want, in normal english, then you can translate those into normal rspec or test unit tests.<p>It&#x27;s a laudable goal, but the abstraction is so leaky in reality it just ends up creating more work for everyone.
moron4hireover 11 years ago
Cucumber, gherkins, capybara, handlebars, sinatra... do these goofy names bother anyone else? I&#x27;m writing code, not hosting a children&#x27;s show.
评论 #6412444 未加载
评论 #6412487 未加载
评论 #6412485 未加载
评论 #6412525 未加载
评论 #6412706 未加载
评论 #6412613 未加载
chrismdpover 11 years ago
It completely depends how you use it. There&#x27;s so much misuse of it out there I can understand why people hate it so much. But done right it&#x27;s an extremely valuable collaboration tool.<p>I&#x27;d recommend the Cucumber Book if you want to read about how to use it well:<p><a href="http://pragprog.com/book/hwcuc/the-cucumber-book" rel="nofollow">http:&#x2F;&#x2F;pragprog.com&#x2F;book&#x2F;hwcuc&#x2F;the-cucumber-book</a><p>I&#x27;ve also blogged a lot about how to use Cucumber well here:<p><a href="http://chrismdp.com/tag/cucumber" rel="nofollow">http:&#x2F;&#x2F;chrismdp.com&#x2F;tag&#x2F;cucumber</a>
评论 #6414243 未加载
mildavwover 11 years ago
Cucumber is part of our workflow and, although I don&#x27;t have a control for this comparison, I think it makes us more efficient. Our product owners write in Gherkin (non-technical != illiterate btw) and can essentially throw the feature files over the wall and any dev can pick it up and get to work. Now, there is conversation around every feature but sometimes only at estimation time.<p>Our POs also use git (non-technical != vcs illiterate) so we have a history of who wrote&#x2F;modified what spec when.<p>Also, we have an <i>additional</i> simple layer of abstraction between feature steps and the actual tests. Most of our step definitions are three line methods that make calls to a ui driver that knows the details of our ui; or to a &quot;given&quot; driver that knows the details of our database&#x2F;models. This ensures that there is only one place where anyone will implement, say, a user logging in.<p><pre><code> Given(&#x2F;^I am a logged in user$&#x2F;) do given.a_logged_in_user end </code></pre> while elsewhere there might be<p><pre><code> Given(&#x2F;^I have signed in$&#x2F;) do given.a_logged_in_user end </code></pre> If the log in process changes, we just edit the given driver.<p>We generally only write golden path features. Edge cases are handled with lower level testing.<p>Our feature files stick to specifying business value rather than ui implementation. For example, we don&#x27;t do this:<p><pre><code> Given I visit the homepage When I enter &quot;children&#x27;s bikes&quot; in the search field And I hit the submit button Then I am on the results page And I see a fieldset with a legend &quot;Children&#x27;s Bikes&quot; And I see a table containing &quot;Huffy Sprite&quot; </code></pre> We would write it like:<p><pre><code> Given I search for a specific product category Then I see the search term I used And the results of the search </code></pre> When a dev needs to work on an app they haven&#x27;t touched in 6 months, it&#x27;s nice for them to read feature files like this to get up to speed on what the app is actually supposed to do. Then can then dig into the ui and given drivers to see how it does it.<p>There is additional infrastructure and PO training involved, but overall, I&#x27;d say cucumber improves clarity and communication on our team.
dlkaover 11 years ago
While there is initial overhead in hooking in the tests, the power comes when you have modularized test steps that you can reuse for multiple tests.<p>At my last company we had QA write all the cucumber tests and someone would hook in the new statements, which is the overhead you suggest. Now if you write 3 different gherkin statements that do the same thing, then that is not optimal.<p>Like many problems, I don&#x27;t think the tool is at fault. It does what it claims. Provides human readable syntax for test cases and lets you hook that in however you want.<p>I think it&#x27;s a valid point to think that extra layer is unnecessary, but I wouldn&#x27;t go as far as discounting it and saying that no company has derived value from it.<p>Like all code, the messes usually stem from how the code is implemented, not the language itself.
bryanlarsenover 11 years ago
Cucumber was most developers first exposure to capybara (IIRC, capybara was developed by the cucumber folks).<p>Since capybara is so awesome, it gave a lot of people a nice impression of cucumber.<p>But unless you actually have a customer in the loop writing cucumber tests, just use the capybara directly.
losvedirover 11 years ago
Not a fan of cucumber. I started it, but the extra layer of abstraction was too much complexity for too little benefit. Instead, I think you can make almost as easy to read and understand acceptance tests with plain old rspec.<p>I just TDD&#x27;ly implemented a &quot;user signs up for Direct Deposit&quot; feature, and the acceptance tests look like this:<p><pre><code> describe &#x27;Direct Deposit&#x27; do before do @workflow = DirectDepositWorkflow.new(create(:user)) end describe &#x27;User sets up direct deposit with correct info.&#x27;, :js do it &#x27;user sees confirmation page - individual&#x27; do @workflow.sign_in_and_visit_direct_deposit_form @workflow.submit_correct_form expect(@workflow).to have_confirmation_message end ... end end </code></pre> Then you can make the workflow spec helper class:<p><pre><code> class DirectDepositWorkflow &lt; Struct.new(:user) include Capybara::DSL include UtilitiesHelper include Rails.application.routes.url_helpers def sign_in_and_visit_direct_deposit_form ... end def submit_correct_form fill_in &#x27;name&#x27;, with: &#x27;John&#x27; click_button &#x27;Submit&#x27; end def has_confirmation_message? page.has_css? &#x27;.success_alert&#x27;, I18n.t(...) end end </code></pre> To me, this is the perfect blend of easy to read, high level specs (serving the rule of cucumber&#x2F;gherkin), with easy to understand, rspec syntax and ordinary method definitions.
评论 #6412711 未加载
slaxoover 11 years ago
&quot;When I write a Cucumber feature, I have to write the Gherkin that describes the acceptance criteria, and the Ruby code that implements the step definitions.&quot;<p>As someone who recently started using cucumber, this was definitely a frustration at first. But after a couple weeks of writing step definitions, and focusing on making them reusable (using some of the tips here: <a href="http://coryschires.com/ten-tips-for-writing-better-cucumber-steps" rel="nofollow">http:&#x2F;&#x2F;coryschires.com&#x2F;ten-tips-for-writing-better-cucumber-...</a> ), I ended up with a pretty good bank of general steps that I could cobble together into new features without much modification. The result was something much more readable and reusable than if I wasn&#x27;t using Gherkin on top of the step definitions.
评论 #6412559 未加载
mattvanhornover 11 years ago
I&#x27;ve posted a response here: <a href="http://mattvanhorn.com/2013/09/19/a-case-for-cucumber/" rel="nofollow">http:&#x2F;&#x2F;mattvanhorn.com&#x2F;2013&#x2F;09&#x2F;19&#x2F;a-case-for-cucumber&#x2F;</a>
评论 #6414050 未加载
评论 #6413551 未加载
paulodeonover 11 years ago
The underlying assumption of this article is that it&#x27;s easier to read code than it is to read english.<p>Well even for a developer of 15 years even the most obtuse English can be more easily absorbed than the cleanest code.<p>The speed of parsing and understanding code is directly related to the amount of time spent writing it and how recently it was read.<p>English can be read and understood at the same speed every time.<p>There is also a non-linear relationship between your feature file size and the underlying code they represent, especially if they represent integration testing. A single feature could test code from 10 different files.<p>For a single developer in an codebase they know and understand well and have recently worked on, Cucumber can act as friction on development.<p>For a single developer who hasn&#x27;t worked on a codebase before, or who is returning to a codebase after some time Cuke steps will definitely improve their ability to understand what the code is doing and by providing a regression test suite improve the quality and probably speed of their output.<p>Code is a language of instruction - not communication, documentation can help, but it is easily forgotten and fails at communicating integration.
keithnoizuover 11 years ago
Assuming you&#x27;re focused on writing reusable steps and building up a solid test architecture I don&#x27;t see cucumber costing you time. You also really shouldn&#x27;t need to go to code that often to debug a test failure. Write better test frameworks, write tests for your tests, and self report issues in your test framework when they come up. E.g. unable to create test fixture -&gt; this-&gt;skipped(&quot;reason&quot;);<p>In my experience the ability to just plug and play steps and quickly add additional coverage for edge cases is a huge bonus for test automation.<p>But again you have to actually engineer things and write reusable steps and intelligent enough test frameworks that you don&#x27;t need to often dig through the test code.<p>I think this issue is somewhat similar to how when writing unit tests you&#x27;ll want to build up a library of reusable custom asserts targeting your domain so you can quickly exercise your sut and validate things. It&#x27;s definitely an upfront costs to build things up like that but in the long run it pays off very nicely when you avoid taking on too much test debt.
评论 #6412852 未加载
评论 #6414432 未加载
algorithmmonkeyover 11 years ago
Disclaimer: I&#x27;m not for or against the use of cucumber.<p>The second claim against cucumber &#x2F; gherkin is not it&#x27;s fault, it&#x27;s the toolset&#x27;s fault. Using grep to find your step definition is not very effective.<p>If you use a tool like Rubymine, you can jump directly to the applicable step definition through one key combination.
评论 #6412629 未加载
评论 #6414006 未加载
fusiongyroover 11 years ago
&gt; Non-technical people don’t read code, no matter how easy it is to read.<p>There is something deep and surprising about this fact.
Arieover 11 years ago
I love cucumber. When you join the development of a project it&#x27;s a great place to start and learn what the project is about.<p>The whole &#x27;customer writes features&#x27; thing never worked for me either, but just having it as automated specifications for my projects makes it very valuable for me.
评论 #6412253 未加载
评论 #6412474 未加载
评论 #6412272 未加载
评论 #6412643 未加载
erikpukinskisover 11 years ago
I drank the Cucumber Kool-Aid and had an app with basically 100% Cucumber coverage. If I wanted to change something, I would first write a cuke for it, write specs as necessary, and only as necessary write actual code.<p>Of course I got into the same spot that almost everyone gets into doing that: too many &quot;and then I click...&quot; scenarios. Great coverage, but then the requirements change substantially and the test base is just a massive snarl of interdependent assumptions. At one point I had effectively written, in cucumber, a natural language interface to my app.<p>But then at some point I needed to <i>move</i> and I needed to move <i>fast</i> and I just let the whole infrastructure rot. Now I&#x27;m doing almost everything on the client side anyway, so it&#x27;s all a little moot.<p>All of that being said, I&#x27;m still a Cucumber fan, but I approach it differently. Here&#x27;s what I think:<p><i>You should have cukes for the 5-10 things that if they don&#x27;t work make your product completely pointless.</i><p>On Gmail, there would be cukes like:<p><pre><code> When I receive the email from Fred about dinner And I open it Then I should see the message When I reply Then Fred should get my reply </code></pre> And those cukes basically don&#x27;t need to have wildcards:<p><pre><code> When &#x2F;^I reply$&#x2F; do click &quot;reply_button&quot; fill_in &quot;message&quot;, :with =&gt; &quot;I&#x27;ll be there!&quot; click &quot;Send&quot; end </code></pre> Essentially:<p>* Use cucumber as a way to force you to keep track of the handful of absolutely critical integrated experiences<p>* Don&#x27;t use fancy grammars... Think of steps as human-readable function names.<p>* Don&#x27;t do anything fancy in the steps. They should just be a list of actions that users would have to do.<p>And yeah, there&#x27;s no reason you couldn&#x27;t do all of this in Steak. I think Cucumber is just nice in that it encourages you to write it out in human terms.
评论 #6414035 未加载
ssi1111over 11 years ago
Towards the end, he says &quot;...but I do enjoy the Gherkin syntax. Not for testing, but for gathering feature requirements...&quot; and this is where cucumber or fit or FitNesse is useful - you gather requirements, then because these requirements can be run as tests you start running these requirements as tests and now you have a living document of your product and product owners can read the tests (which are the requirements). If you look at such tools as mere test runners, then they do add an extra layer of complexity, but these tools were not meant to be just test runners... so you are using it for the wrong thing... :)
ripterover 11 years ago
We started using Cucumber 6 months ago and I hate it. My biggest issue is that it&#x27;s unreliable. 90% of the test failures work if you do it exact same steps manually.<p>It seems like it always times out waiting for something on the page to load.
评论 #6412423 未加载
solisticeover 11 years ago
Damnit, I was hoping for an article about the health drawbacks of cucumber (I&#x27;m boring that way), and it&#x27;s about another Framework.<p>It&#x27;d be awesome if people started tagging these as [technical] or [computers] or [vegetable-afficionados].<p>Rant out.
goldvineover 11 years ago
&quot;I don’t prefer to use Cucumber for any of my testing, but I do enjoy the Gherkin syntax. Not for testing, but for gathering feature requirements. It provides a very clear and concise way of explaining a feature, without confusion. But that is where the line is drawn.&quot;<p>That is also where I draw the line. The whole argument that other non-technical folks can read Gherkin may be true, but I can&#x27;t imagine them enjoying it.<p>It&#x27;s like reading computer-speak. Why can&#x27;t features just be described in English...?
jrochkind1over 11 years ago
Yes. And he&#x27;s not the first one to say this. There was a post saying the exact same thing about a year ago, maybe even on HN?<p>But, yes, just yes.<p>(I&#x27;d go even further and say &quot;why rspec when you can test::unit&#x2F;minitest? especially for Rails since the minitest path is officially supported by rails.&quot; Again, the extra layer of stuff is just more stuff to understand and troubleshoot when your tests aren&#x27;t working as you&#x27;d like -- for unclear benefit.)
enry_strakerover 11 years ago
The thread seems to be overrun by a bunch of whiny crybabies.<p>No one forces people to use them, yet they seem to have a great time crying about it without trying to defend their position.<p>Cucumber and RSpec are among a set of testing tools which has really changed the testing landscape. It would be really wonderful if people spent half this time and energy on trying to create a better tool or joining the open source groups of Cucumber and RSpec and trying to make it better.
评论 #6412815 未加载
viggityover 11 years ago
I&#x27;m a .net dev so I&#x27;ve been using SpecFlow (which uses Gherkin) and frankly, I love it. I write a happy path and a sad path for my scenarios, make sure my step definitions are well parameterized and my QA can go off and create as many new scenarios to test all the edge cases he wants. It works wonderfully.
adamb0mb1over 11 years ago
As a product&#x2F;program manager... I can tell you that writing RSpec tests are just as easy to write as Cucumber tests. And, with less overhead.
malkiaover 11 years ago
Really, I&#x27;m not a Ruby guy, so I thought it&#x27;s some vegetable story... cause I love cucumbers (&amp; tomatoes)... Ah...
liveinoaklandover 11 years ago
Figured the bottom voted comment would be about the virtues of fresh cucumber.