Benefits of Behavior Driven Development

December 21, 2017    Development UnitTesting DevOps BDD AutomatedTesting

Benefits of Behavior Driven Development

Note: Originally posted on GeeksWithBlogs.net on July 26, 2013. These thoughts are still with me and valid today.

Continuing my previous article on BDD , I wanted to point out some benefits of BDD and since BDD is an extension of Test Driven Development (TDD), you get those as well.

There are many articles about the benefits of TDD and they apply to BDD. I’ve pointed out some here and copied some of the main points for each article, but there are many more including the book The Art of Unit Testing by Roy Osherove .

Lee Brandt’s 2008 article

  • Stability
  • Accountability
  • Design Ability
  • Separated Concerns
  • Progress Indicator

http://tddftw.com/benefits-of-tdd/

  • Help maintainers understand the intention behind the code
  • Bring validation and proper data handling concerns to the forefront.
  • Writing the tests first is fun.
  • Better APIs come from writing testable code.
  • TDD will make you a better developer.

Take a look at the slides , especially the extra time required for TDD (slide 10) and the next one of the bugs avoided using TDD (slide 11).

  • Less bugs (slide 11)
  • about testing and development (13)
  • Increase confidence in code (14)
  • Fearlessly change your code (14)
  • Document Requirements (14) also see
  • Discover usability issues early (14)

All these points and articles are great and there are many more. The following are my additions to the benefits of BDD from using it in real projects for my company.

July 2013 on MSDN - Behavior-Driven Design with SpecFlow

Scott Allen did a very informative TDD and MVC module, but to me he is doing BDD

Compile and Execute Requirements in Microsoft .NET ~ Video from TechEd 2012 Communication

I was working through a complicated task that the decision tree kept growing. After writing out the Given, When, Then of the scenario, I was able tell QA what I had worked through for their initial test cases. They were able to add from there. It is also useful to use this language with other developers, managers, or clients to help make informed decisions on if it meets the requirements or if it can simplified to save time (money).

Thinking through solutions, before starting to code.

This was the biggest benefit to me. I like to jump into coding to figure out the problem. Many times I don’t understand my path well enough and have to do some parts over. A past supervisor told me several times during reviews that I need to get better at seeing “the forest for the trees”. When I sit down and write out the behavior that I need to implement, I force myself to think things out further and catch scenarios before they get to QA.

A co-worker that is new to BDD and we’ve been using it in our new project for the last 6 months, said “It really clarifies things”. It took him awhile to understand it all, but now he’s seeing the value of this approach (yes there are some downsides, but that is a different issue).

Developers’ Confidence

This is huge for me. With tests in place, my confidence grows that I won’t break code that I’m not directly changing. In the past, I’ve worked on projects with out tests and we would frequently find regression bugs (or worse the users would find them). That isn’t fun. We don’t catch all problems with the tests, but when QA catches one, I can write a test to make sure it doesn’t happen again.

It’s also good for Releasing code, telling your manager that it’s good to go.

As time goes on and the code gets older, how confident are you that checking in code won’t break something somewhere else?

Merging code - pre release confidence

If you’re merging code a lot, it’s nice to have the tests to help ensure you didn’t merge incorrectly.

Interrupted work

I had a task that I started and planned out, then was interrupted for a month because of different priorities. When I started it up again, and un-shelved my changes, I had the BDD specs and it helped me remember what I had figured out and what was left to do. It would have much more difficult without the specs and tests.

Testing and verifying complicated scenarios

Sometimes in the UI there are scenarios that get tricky, because there are a lot of steps involved (click here to open the dialog, enter the information, make sure it’s valid, when I click cancel it should do {x}, when I click ok it should close and do {y}, then do this, etc….). With BDD I can avoid some of the mouse clicking define the scenarios and have them re-run quickly, without using a mouse. UI testing is still needed, but this helps a bunch.

The same can be true for tricky server logic.

Documentation of Assumptions and Specifications

The BDD spec tests (Jasmine or SpecFlow or other tool) also work as documentation and show what the original developer was trying to accomplish. It’s not a different Word document, so developers will keep this up to date, instead of letting it become obsolete.

What happens if you leave the project (consulting, new job, etc) with no specs or at the least good comments in the code?

Sometimes I think of a new scenario, so I add a failing spec and continue in the same stream of thought (don’t forget it because it was on a piece of paper or in a notepad). Then later I can come back and handle it and have it documented.

Jasmine tests and JavaScript –> help deal with the non-typed system

I like JavaScript, but I also dislike working with JavaScript. I miss C# telling me if a property doesn’t actually exist at build time. I like the idea of TypeScript and hope to use it more in the future. I also use KnockoutJs, which has observables that need to be called with ending (), since the observable is a function. It’s hard to remember when to use () or not and the Jasmine specs/tests help ensure the correct usage.

This should give you an idea of the benefits that I see in using the BDD approach. I’m sure there are more. It talks a lot of practice, investment and experimentation to figure out how to approach this and to get comfortable with it. I agree with Scott Allen in the video I linked above “Remember that TDD can take some practice. So if you’re not doing test-driven design right now? You can start and practice and get better. And you’ll reach a point where you’ll never want to get back.”



Watch the Story for Good News
I gladly accept BTC Lightning Network tips at [email protected]

Please consider using Brave and adding me to your BAT payment ledger. Then you won't have to see ads! (when I get to $100 in Google Ads for a payout, I pledge to turn off ads)

Use Brave

Also check out my Resources Page for referrals that would help me.


Swan logo
Use Swan Bitcoin to onramp with low fees and automatic daily cost averaging and get $10 in BTC when you sign up.