1

I am now working on a project where we are using cucumber-jvm to drive acceptance tests.

On previous projects I would create internal DSLs in groovy or scala to drive acceptance tests. These DSLs would be fairly simple to use such that even a non-techie would be able to write tests with a little bit of guidance.

What I see is that BDD adds another layer of indirection and semantic sugar to the tests, but I fail to see the value-add, especially if the non-techies can use an internal DSL.

In the case of cucumber, stepDefs seem to scatter the code that drives any given test over several different classes, making the test code difficult to read and debug outside the feature file. On the other hand putting all the code pertaining to one test in a single stepDef class discourages re-use of stepsDefs. Both outcomes are undesirable, leaving me asking what is the use of natural language worth all this extra, and unintuitive indirection?

Is there something I am missing? Like a subtle philosophical difference between ATDD and BDD? Does the former imply imperative testing whereas the latter implies declarative testing? Do these aesthetic differences have intrinsic value?

So I am left asking what is the value add to justify the deterioration in the readability of the actual code that drives the test. Is this BDD stuff actually worth the pain? Is the value add more than just aesthetic?

I would be grateful if someone out there could come up with a compelling argument as to why the gain of BDD surpasses the pain of BDD?

murungu
  • 2,090
  • 4
  • 21
  • 45
  • 1
    To me the largest difference is the focus. ATDD is more focused on what the developer is trying to achieve, BDD is more focused on the value the business owner is trying to achieve. I think either of them are fantastic and would use the one that fit better in my organization. In the end, a better product is a result of early involvement with stakeholders and both methods achieve that. Personally, I don't experience BDD pain, but that's just me. – Jeff Price Nov 16 '15 at 16:30
  • it adds value in that everybody can see what the user is doing and seeing. New people on the team can see why a feature is there and what it does... in plain English (or whatever lang your team uses). – Dave McNulla Nov 16 '15 at 20:36
  • @JeffPrice "ATDD is more focused on what the developer is trying to achieve, BDD is more focused on the value the business owner is trying to achieve." And therein lies the rub. The pain arises when you attempt to use the latter (BDD), for the purpose of the former (what the developer is trying to achieve). IMHO BDD should be used sparingly with an intense focus on what the user wants and sees, not on everything the application does. – murungu Nov 16 '15 at 21:19
  • @JeffPrice If you agree with my comment (above) I will accept your comments as an answer. Could you add a word or two about BDD being the more user-centric activity.For example if an online retail application does a bulk dispatch of orders at 2:00 am in the morning, that is not does not really something the user will see (good use case for ATDD). The user will however add things do their shopping cart (good use case for BDD). – murungu Nov 16 '15 at 21:26

2 Answers2

2

What I see is that BDD adds another layer of indirection and semantic sugar to the tests, but I fail to see the value-add, especially if the non-techies can use an internal DSL.

The extra layer is the plain language .feature file and at the point of creation it has nothing to do with testing, it has to do with creating the requirements of the system using a technique called specification by example to create well defined stories. When written properly in the business language, specification by example are very powerful at creating a shared understanding. This exercise alone can both reduce the amount of rework and can find defects before development starts. This exercise is otherwise known as deliberate discovery.

Once you have a shared understanding and agreement on the specifications, you enter development and make those specifications executable. Here is where you would use ATDD. So BDD and ATDD are not comparable, they are complimentary. As part of ATDD, you drive the development of the system using the behaviour that has been defined by way of example in the story. the nice thing you have as a developer is a formal format that contains preconditions, events, and postconditions that you can automate.

Here on, the automated running of the executable specifications on a CI system will reduce regression and provide you with all the benefits you get from any other automated testing technique.

These really interesting thing is that the executable specification files are long-lived and evolve over time and as you add/change behaviour to your system. Unlike most Agile methodologies where user stories are throw-away after they have been developed, here you have a living documentation of your system, that is also the specifications, that is also the automated test.

Let's now run through a healthy BDD-enabled delivery process (this is not the only way, but it is the way we like to work):

  1. Deliberate Discovery session.
    • Output = agreed specifications delta
  2. ATDD to drive development
    • Output = actualizing code, automated tests
  3. Continuous Integration
    • Output = report with screenshots is browsable documentation of the system
  4. Automated Deployment
    • Output = working software being consumed
  5. Measure & Learn
    • Output = New ideas and feedback to feed the next deliberate discover session

So BDD can really help you in the missing piece of most delivery systems, the specifications part. This is typically undisciplined and freeform, and is left up to a few individuals to hold together. This is how BDD is an Agile methodology and not just a testing technique.

With that in mind, let me address some of your other questions.

In the case of cucumber, stepDefs seem to scatter the code that drives any given test over several different classes, making the test code difficult to read and debug outside the feature file. On the other hand putting all the code pertaining to one test in a single stepDef class discourages re-use of stepsDefs. Both outcomes are undesirable, leaving me asking what is the use of natural language worth all this extra, and unintuitive indirection?

If you make the stepDefs a super thin layer on top of your automation testing codebase, then it's easy to reuse the automation code from multiple steps. In the test codebase, you should utilize techniques and principles such as the testing pyramid and the shallow depth of test to ensure you have a robust and fast test automation layer. What's also interesting about this separation is that it allows you to ruse the code between your stepDefs and your unit/integration tests.

Is there something I am missing? Like a subtle philosophical difference between ATDD and BDD? Does the former imply imperative testing whereas the latter implies declarative testing? Do these aesthetic differences have intrinsic value?

As mentioned above, ATDD and BDD are complimentary and not comparable. On the point of imperative/declarative, specification by example as a technique is very specific. When you are performing the deliberate discovery phase, you always as the question "can you give me an example". In that example, you would use exact values. If there are two values that can be used in the preconditions (Given) or event (When) steps, and they have different outcomes (Then step), it means you have two different scenarios. If the have the same outcome, it's likely the same scenario. Therefore as part of the BDD practice, the steps need to be declarative as to gain the benefits of deliberate discovery.

So I am left asking what is the value add to justify the deterioration in the readability of the actual code that drives the test. Is this BDD stuff actually worth the pain? Is the value add more than just aesthetic?

It's worth it if you are working in a team where you want to solve the problem of miscommunication. One of the reasons people fail with BDD is because the writing and automation of features is lefts to the developers and the QA's, and the artifacts are no longer coherent as living specifications, they are just test scripts.

Test scripts tell you how a system does a particular thing but it does not tell you why.

I would be grateful if someone out there could come up with a compelling argument as to why the gain of BDD surpasses the pain of BDD?

It's about using the right tool for the right job. Using Cucumber for writing unit tests or automated test scripts is like using a hammer to put a screw into wood. It might work, but it's never pretty and it's always painful!

On the subject of tools, your typical business analyst / product owner is not going to have the knowledge needed to peek into your source control and work with you on adding / modifying specs. We created a commercial tool to fix this problem by allowing your whole team to collaborate over specifications in the cloud and stays in sync (realtime) with your repository. Check out Simian.

I have also answered a question about BDD here that may be of interest to you that focuses more on development:

Should TDD and BDD be used in conjunction?

Community
  • 1
  • 1
Xolv.io
  • 2,483
  • 1
  • 15
  • 17
0

Cucumber and Selenium are two popular technologies. Most of the organizations use Selenium for functional testing. These organizations which are using Selenium want to integrate Cucumber with selenium as Cucumber makes it easy to read and to understand the application flow.    Cucumber tool is based on the Behavior Driven Development framework that acts as the bridge between the following people: 

  1. Software Engineer and Business Analyst. 
  2. Manual Tester and Automation Tester. 
  3. Manual Tester and Developers. 

Cucumber also benefits the client to understand the application code as it uses ​Gherkin language which is in Plain Text. Anyone in the organization can understand the behavior of the software.  The syntax's of Gherkin is in the simple text which is ​readable and understandable​.