Post

Which library is the best for writing BDDs in Python & listening to your tests

pip install BDD?

There are two popular libraries that help writing BDD specifications in Python - pytest-bddand behave.

Both are popular, actively maintained and feature-complete. I worked with both of them in the past and I spotted no serious issues (anecdotal evidence, your mileagage may wary).

Success with BDDs doesn’t depend on the tool, though. I recently read a book Specification by Example by Gojko Adzic. It emphasizes that tools are not what’s causing issues with specifications and also tools won’t fix them.

I strongly recommend Gojko’s book. It has a lot of insights and is based on a solid research, not author’s gut feelings.

Why do we even do BDD?

The goal of BDDs (or other form of executable specifications) IS NOT testing. It’s ensuring an ongoing collaboration between stakeholders, developers, testers and business analysts (or whoever participates in your dev process). Second goal is having an ever-green, executable documentation. Lastly, BDDs are giving great hints about architecture smells.

Which brings us to second topic today, listening to your tests (or specs as Gojko put it).

Listening to your tests

Turns out there’s a huge overlap between BDD and DDD. Simply saying, if you find it hard to write down a scenario using Gherkin, it may mean your underlying architecture is too convoluted or you’re trying to specify too much at once. In DDD terms, you may have missed a subdomain.

Dan North shows it perfectly in an article:

For more interesting cases regarding BDDs see this case study, from three different angles:

Of course, BDD is not a silver bullet and it won’t provide sufficient nor convenient full test coverage. Some tests are simply more technical and those don’t fit into specifications.

Wardley Maps

Gilectomy (again)

IoC containers in Python

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.