API Design Using Behavior Driven Development
Editorial Note: I originally wrote this post for the SmartBear blog. You can check out the original here, at their site. While you’re there, take a look at some of their products in the code review, testing, and API spaces.
Test-driven development (TDD) has been around for a while now. Behavior-driven development (BDD) is a comparably recent methodology that emerged from the practice of TDD. It could reasonably be called a narrower application of TDD.
TDD is a process where one uses a failing unit test to express a shortcoming of the system. The next step is then to modify the production code to get the failing test to pass, without making existing tests fail. BDD more or less takes this same concept and adds to it the idea that the tests should be written in easy-to-understand language about the problem domain, and that they should express user acceptance criteria.
So instead of
void testErrorMessageOnNull()
you would have
Given a text box that has been left empty, when I click submit, I should receive an error message.
As a practice, this has found its way into the agile canon, and given rise to something conversationally termed, “three amigos.” This is a practice wherein a representative of “the business,” a tester, and a developer get together and agree on what a requested feature is, what it means, what it looks like when done, and how to verify completion. In teams practicing BDD, the output of this conversation will often be an acceptance test, expressed in the Gherkin specification language. When added to the codebase, this test will, of course, fail. The folks implementing the feature know that they’re done when they’ve succeeded in making the test pass.
If we put agile aside for a minute, this is a pretty common sense approach for any team. The essence of it is, “let’s define and be clear about what success looks like and then automate a check for it.” So you don’t need to be an agile team for this to make sense — you just need to be a team looking for clarity.






