Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between BDD and specifications by example?

Tags:

bdd

I know BDD and also read Specification by Example the great book by Gojko Adzic; As I understand they are almost the same and have many in common; But I was not able to understand their main difference. I mean Can we use them interchangeably?

like image 741
Alireza Rahmani khalili Avatar asked Mar 27 '26 08:03

Alireza Rahmani khalili


1 Answers

General idea

BDD is the format of describing tests in a form of "this functionality does this and that". If requirements are written in the same format, then we end up with the whole team using BDD. Because these requirements can be reused for testing.

Specs by example is.. well, putting a particular example into the requirements.

Testing formats

BDD-for-testing can come in different forms:

  • Given When Then
  • Gherkin (a more strict dialect of G/W/T used by Cucumber family of frameworks)
  • Describe-it (Jasmine, Mocha, etc)
  • Or something custom. Could be same old JUnit with tests named as "adminHasAccessToProfileOfOthers" instead of older style "testAdminCanAccessProfileOfOthers"

Requirements

As for BDD-for-requirements, here's an example:

If user has sufficient amounts of money, they can buy the product

And here is Specs-by-example:

If user has 10$ and the product is 9$, user can buy that product

See, in the 1st example we used abstract ideas, while in the latter one we used particular values.

Oftentimes when people talk about BDD/Specs-by-example, they would write requirements using Given-When-Then. But as an abstract idea this isn't compulsory - it's just what most testing frameworks support it.

Overall, BDD is a very good idea for testing, especially if it's not a Given-When-Then :) But when it comes to requirements - I haven't seen any project in my experience that really benefited from it.

As for other common misconceptions: BDD and how it does NOT relate to TDD.

like image 179
Stanislav Bashkyrtsev Avatar answered Mar 28 '26 22:03

Stanislav Bashkyrtsev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!