Behavior-driven development in Haskell

I am looking for a library to do some Behavior-Driven Development in Haskell.

Looking on Hackage I was able to find only chuchu: Behaviour Driven Development like Cucumber for Haskell which looks abandoned, last commit beeing more than 10 years old.

Is there someone who knows or uses some other tool or library to do BDD with Haskell?

1 Like

I believe behavioral tests are often called ‘golden’ tests (as in gold standard). If you look at Hackage, there are various testing packages for such tests, such as tasty-golden

Thanks, that could be something to look into, but I fear golden test are not the same thing as DBB

Would you be able to describe BDD in your own words?

At my workplace, BDD is synonym with specifying the behavior of software (inputs and expected outputs) separately from the software itself, usually in some structured files (e.g. YAML). In this way, the behavior of software can be specified before any software is actually written.

The package you have linked (chuchu) appears to be doing this in an embedded domain-specific language:

  • Given → initial state;
  • When → test inputs;
  • Then → expected outputs.

Is an embedded domain-specific language a requirement for you?

1 Like

As I see it, BDD is a way of writing tests writing user stories with the domain language.

From my experience, many DBB frameworks in other languages (the most famous one is Cucumber) use a language called Gherkin

Thanks for the explanation. We’ve apparently been using our own version of Gherkin, but I’m not aware of something you can use off-the-shelf in Haskell.

1 Like

This is basically what hspec is. I don’t think people tend to use it that well, but, e.g.:

https://hackage.haskell.org/package/hspec-2.11.3/docs/Test-Hspec.html#v:pending

Gherkins make you write tests in a total different way from Hspec.
It is supposed to look like natural language and it’s designed to be used by non-developpers.
Also, it allows you check successive steps of the same test (without reexecuting from the beginning each time), which corresponds to nested it (I’m not sure if Hspec allows it).
In practice it becomes quickly a pain and you indeed approximate it with Hspec and make your own testing eDSL.

IMO, the philosophy at the core of BDD is essentially just “write readable tests”. Which is an admirable goal, and probably more achievable in Haskell than in most languages since, as we know, it’s great for writing EDSLs.

Having been forced to use Cucumber/Gherkin specifically once in the past, I’m very skeptical about its utility. There are endless Hacker News threads about why it doesn’t really work out in practice. And this Haskell Cafe thread always amuses me, even if you could argue it misses the point slightly.

4 Likes

I guess it depends on what you want to get out of it. My experience with “natural language” is that it’s not particularly clear to most people.

I imagine you don’t need much explanation to get a non-programmer reading a (pending’d out) hspec test or to read the output of the test run, but getting a non-programmer to write any cucumber tests is pretty much a non-starter.

So any realistic goal I can imagine here is achievable with hspec.

That said, I don’t like writing tests in this form anyway. It seems to be formalizing something I don’t care as much about.

1 Like

I agree with you and in my experience, Guerkins is terrible. I was just pointing that is what the OP seem to be looking for (regardless of whether it is a good idea or not).

1 Like