Live data from Hacker News

Cucumber lets you write automated tests in plain language

cucumber.io

51–60 of 76 posts

Re: Cucumber lets you write automated tests in plain language

#51
post #49

Earlier quoted context omitted.

I use executable specs quite a lot with stakeholders. I'd never ask them to write them, but I will often write a spec/test based upon their two sentence jira and then screenshare and walk them through my interpretation to get feedback early (i.e. before ive wasted time building the wrong thing). Cucumber/gherkin is awful at this of course, and the regex thing was a terrible idea but it's not the only tool. The idea t…

Hey, could you please share what you use for writing your specs? Pure python? Or some DSL?

hitchstory. typed YAML over python.

Re: Cucumber lets you write automated tests in plain language

#52
post #46

Earlier quoted context omitted.

I use executable specs quite a lot with stakeholders. I'd never ask them to write them, but I will often write a spec/test based upon their two sentence jira and then screenshare and walk them through my interpretation to get feedback early (i.e. before ive wasted time building the wrong thing). Cucumber/gherkin is awful at this of course, and the regex thing was a terrible idea but it's not the only tool. The idea t…

> The idea that tests should be split into a specification layer and execution layer is a good one that should have taken off by now. There is a fundamental reason it hasn't: An actual specification layer isn't any simpler than the execution layer. That's a programmer's fallacy. What has taken off, and is part of virtually every software project, is a loose, natural language specification, which hints at "more or les…

>An actual specification layer isn't any simpler than the execution layer.

The point of separation of concerns isnt to keep the simple layer separate from the complex one. It's to simplify the whole thing by only addressing one concern per layer.

Unit tests are often a pain in the ass to read because they are a mess of implementation and specification details. No separation.

>You can't solve the problem in that way. Because, from a high-level stakeholder's perspective, the whole point of the people below them (whether programmers or UX designers or anyone else) is to fill in those details in a way that matches their own hazy expectations

If you crystallize the hazy expectations on their behalf and skip feeding it back to them then you will often find out that "thats not what i meant" after the code is complete.

Those mistakes are expensive and avoidable.

Re: Cucumber lets you write automated tests in plain language

#54
post #46

Earlier quoted context omitted.

> The idea that tests should be split into a specification layer and execution layer is a good one that should have taken off by now. There is a fundamental reason it hasn't: An actual specification layer isn't any simpler than the execution layer. That's a programmer's fallacy. What has taken off, and is part of virtually every software project, is a loose, natural language specification, which hints at "more or les…

>An actual specification layer isn't any simpler than the execution layer. The point of separation of concerns isnt to keep the simple layer separate from the complex one. It's to simplify the whole thing by only addressing one concern per layer. Unit tests are often a pain in the ass to read because they are a mess of implementation and specification details. No separation. >You can't solve the problem in that way.…

Oh I understand the standard arguments. I just don't agree with them.

> The point of separation of concerns isnt to keep the simple layer separate from the complex one. It's to simplify the whole thing by only addressing one concern per layer.

With some caveats, I think this is just a fiction. There can be some value in having high-level tests and low-level tests, but not because it removes complexity. It can help with focus and priority. Which is a problem that can be solved in many ways.

> If you crystallize the hazy expectations on their behalf and skip feeding it back to them then you will often find out that "thats not what i meant" after the code is complete.

But this is exactly what they want you to do, and do well enough that "that's not what i meant" is not a big problem. They certainly don't want to read cucumber tests as a way of ensuring you're on the same page. They will tolerate rough, incremental prototypes, per the old agile advice, and this is probably still the best way of solving the communication gap problem.

Re: Cucumber lets you write automated tests in plain language

#55

In my misspent youth I've tried to introduce Cucumber/Gherkin a couple of different times but it's something with a deceptive promise. The preconditions are that you have domain experts or business people interested and willing to engage in writing or reviewing these tests. Unless you have this and it's something that those people are going to sustain when the going gets tough you're just making writing tests harder…

Yeah this was unfortunately my experience too. A lot of head nodding and a token effort up front but they quickly reverted back to playing telephone on Jira tickets. A year or two later we're slowly ripping out the cucumber tests and replacing them with tests in our implementation language.

It's a two way street. I'd highly recommend never implementing it unless product is the one driving it, and actually makes it a priority.

Re: Cucumber lets you write automated tests in plain language

#56
I've commented elsewhere on lack of buy-in from stakeholders as a huge pitfall.

On a technical level, cucumber is also at odds with the need for a test suite to be easily maintainable. What I mean is that each test (especially e2e tests) will want to do some setup/initialization. This is usually expressed as step definitions.

Over time, an undisciplined team may write several slightly different but effectively identical step definitions. They may also combine multiple steps into bigger steps because usually a spec writer doesn't want to exhaustively define every piece of setup, they just want to write "Given all 200 pieces of input data and mocks are magically in the right place..."

I was able to wrangle the specs into composability using Rule and Background blocks, but at that point we were just programming tests with a shitty layer over the actual code.

Re: Cucumber lets you write automated tests in plain language

#57
post #43

I am very much for internal DSLs for functional testing, but have never seen the point of external DSLs (it feels wrong that anyone but the implementing team could or should create or maintain them). I passionately believe you should refactor and use abstractions in your test code thought, and in my experience that ends up looking quite like parameterised steps (again, in code rather than English preferably).

We did a lot of this where I work to make using cucumber easier, and when we later stripped cucumber out it still was incredibly useful.

Re: Cucumber lets you write automated tests in plain language

#58
> Cucumber lets you write automated tests in plain language

No, it doesn't.

Or to be more precise: Cucumber lets you write your tests twice - once in something that isn't nearly as close "plain language" as it seems at first glance, and then again in a horrible mismash of regex spaghetti code that will make you wish you'd been born a thousand years before computers were invented.

I was forced to try to use it about 15 years ago and spent literally twice as much time debugging the testing framework as I did actually implementing code - velocity on actual feature development ground to a halt. I think the most hilarious part about this was that it was completely incapable of finding the most common class of problem we tended to run into at the time - cross-browser presentation issues.

One of the big problems you'll find if you try to use this trash is that nobody except a software engineer will be really able to write tests in a consistent enough way that you'll be able to implement them without a truly horrible regex soup: even if you can actually get a non-software-engineer to write cucumber tests for you (dubious), the non-engineer-types will write "given I'm logged in" for one test and then "given I have logged in" for another, and "given I gave gone through the login process" for a third. And it doesn't matter how many regexs you implement to try to cover all their variations in their language, or how clever your regexs are - the nature of natural language means there's near-infinite variations, and they'll come up with new and more annoying variations just when you start feeling confident. And that's before we even start talking about the ambiguity of natural language.

I did manage to find a decent use for cucumber-style language a couple of years ago, though - we started commenting our unit tests using this style:

  def test_something():
     """ test some thing """

     # given some prerequisite
     set_up_prerequisite()

     # when I perform some action
     perform_some_action()

     # then some condition should be true, because 
     assert some_condition is True

At first I was dubious, given my previous experience, but I quickly found this to be a very nice way to document your unit tests and make them super-readable and easy to understand at a glance. And you don't even need to install any software to start doing it. I highly recommend it!

Re: Cucumber lets you write automated tests in plain language

#60

I wish the doctest approach won over the BDD approach. I still find myself recreating the doctest approach in miniature... Specifically I try to make a nice string representation of state, and then tests match off that state. So for instance I don't want to say expect(x.length).toBe(0) (one syntax, Cucumber goes further in that syntactic direction). Because if the length is 1 then 1!=0 is a very opaque failure. Or if…

In elixir land, the doctest is a common sight. I wouldn't say it won out over the unit test, but it's still fairly common
Post reply on HN