Background

« Table of Contents »
Previous « The Behaviour Specification Handbook

The Behaviour Specification Handbook

Background

This first chapter in The Behaviour Specification Handbook provides a quick overview of Behaviour-Driven Development (BDD), how it can help to reduce the costs of software development, and how to scale it to large solutions.

  1. Behaviour-Driven Development (BDD) Overview
  2. Scaling BDD To Large Solutions
  3. What Is A Software Component?


Next » Behaviour-Driven Development (BDD) Overview


Next Chapter » Behaviour Specifications

Behaviour Specifications Before Implementation

« Table of Contents »
Previous « The Implementation Process

The Behaviour Specification Handbook

The Implementation Process

Behaviour Specifications Before Implementation

Behaviour Specifications are actual program specifications, and as such, it is common sense that the Behaviour Specifications should be written before attempting to do any coding of a software component.

If however, you are retrofitting behaviours for an existing software component, then you are in an interesting and potentially dangerous situation. The danger is that the team, when writing the specifications, could be too heavily influenced by the existing code and known internal implementation details, rather than writing Behaviour Specifications that better represent the core business requirements. Unless the team is at a mature level of writing Behaviour Specifications in common business language, I recommend that, at least for a large portion of the time allocated to write the specifications, pretend as if the code has not been written already. Either way, the team should keep referring back to the core business requirements, and perhaps only using the code to ensure that everything remains on track. Be careful and do not assume that the code is correct! Do not be surprised if you discover some defects!


Next » The Roles Of Developers and Test Analysts

Behaviour Specifications

« Table of Contents »
Previous Chapter « Background

The Behaviour Specification Handbook

Behaviour Specifications

This chapter in The Behaviour Specification Handbook provides a definition of Behaviour Specifications, and an overview of the Gherkin language and feature files.

  1. What Are Behaviour Specifications?
  2. No Other Test Cases Are Necessary!
  3. Developers: No Other Automated Tests!
  4. Overview Of The Gherkin Language
  5. Thoughts On Gauge
  6. Feature Files
  7. Feature Names
  8. What Is A Behaviour Specification Description?


Next » What Are Behaviour Specifications?


Next Chapter » The Behaviour Specification Writing Process

Behaviour-Driven Development (BDD) Overview

« Table of Contents »
Previous « Background

The Behaviour Specification Handbook

Background

Behaviour-Driven Development (BDD) Overview

The software engineering practices and processes of Behaviour-Driven Development (BDD) that I promote focuses a team on delivering software solutions with high business value, higher quality and less defects. BDD encourages and helps to facilitate close collaboration and clear communication between team members and with business stakeholders.

With BDD, it is possible to deliver solutions that better satisfy actual business requirements and have a lower on-going maintenance and total cost to the business. This can only be achieved however, if the team maintains professional discipline, follows the processes and performs the software development activities, in the recommended order.

One of the key practices in BDD, and the focus of this handbook, is the Behaviour Specification writing sessions. Behaviour Specification writing sessions should be attended by multiple roles in the team, before the coding of a specific piece of functionality is started. This one practice, guided by concrete examples or use cases, has the simple and significant effects of optimising the design, review, and testing feedback cycle by:

  • Ensuring what is to be delivered is actually required;
  • Ensuring what is to be delivered is valuable to the business;
  • Ensuring what is to be delivered is within the agreed scope of functionality;
  • Ensuring what is to be delivered is well understood by the team;
  • Clearly specifying the required behaviour of each software component in everyday common business language that anyone in the team (including business stakeholders) can understand; and
  • Each attendee mentally testing the requirements and software component specifications against the proposed design.

The Behaviour Specification writing sessions encourage and cause important discussions, questions and healthy debates to take place. The result is a common and well-understood, mentally tested and agreed solution — before development has started. There is therefore a significant reduction in the risk of defects and missing or ambiguous functionality early in the software development lifecycle, when it is the cheapest and most appropriate time to have those discussions and identify potential issues.

The clear communication is achieved by everyone in the team discussing required software behaviour or functionality in the business’s everyday common language. If for some reason the common business language unfortunately is ambiguous in some areas, then that is a wonderful opportunity to highlight the risk and show leadership to the business by suggesting and helping to implement some positive, clarifying terminology changes!

As you know, team members will come and go over time. Current and future team members however, may not have the same level of competency, business analysis capability or technical skills. This is why the software specifications are written in the everyday language of the business. Every team member (or interested business stakeholder) who understands the business (the lowest common denominator) — regardless of their technical competency — should be able to understand the functionality that is to be or has been delivered. The total cost over time of software development, maintenance, resourcing and on-boarding is reduced because of this simple concept.

The resulting artefacts typically produced in the process of BDD include living documentation (also known as executable program specifications) and other test assets, such as the test run reports for the executed specifications.

There are many articles available that introduce and discuss the beginnings and benefits of BDD. Instead repeating similar information, below is some recommended reading material:


Next » Scaling To Large Solutions

Code!

« Table of Contents »
Previous « Identify Who Will Code The Automation Or Manually Perform Each Test

The Behaviour Specification Handbook

The Implementation Process

Code!

It is time to code — and all the developers in the team roll their eyes and mutter “finally”!

A developer should choose one of the Behaviour Specifications they agreed to implement and do just enough coding to fulfil that specification and also implement the automated test for it. Simple – rinse and repeat with the next behaviour.

Whether or not a developer follows the Test-Driven Development (TDD) practice of Red-Green-Refactor is a personal choice. If a developer wants to, then they can implement the test automation code first. That approach has no effect on the practice of BDD, but depending on the skill of the developer, it can result in code that is more easily testable.

Developers also should remember not to write any automated tests other than those specified by the behaviours.


Next » Separate Implementation Of Unit Test Steps From Integration Test Steps

Developers: No Other Automated Tests!

« Table of Contents »
Previous Page « No Other Test Cases Are Necessary!

The Behaviour Specification Handbook

Behaviour Specifications

Developers: No Other Automated Tests!

Developers in particular need to understand that they should not write any automated tests other than those that are specified by the Behaviour Specifications. Developers love writing code, and many love writing automated tests (although contrarily, many do not!). Even when the team together has specified all the required behaviours, some developers can still feel as if they should write more automated tests when they are coding.

If this is the case, it is possible that the developers need to better understand the premise and comparative benefits of Behaviour-Driven Development and also the concept of Equivalence Partitioning.

Benefits Of Behaviour-Driven Development

In previous eras of Test-Driven Development, it was common for developers to write many automated tests for each method within each different class or module. Some of the issues with that approach include:

  • A high maintenance cost of automated test assets due to brittle tests that must be refactored when the code is refactored;
  • Communication issues between developers and the rest of the team — some developers can find it difficult to effectively describe the automated tests they are coding on a daily basis. This lack of communication can lead to other team members questioning and arguing the value of such activities.
  • Developers can struggle to estimate when they will finish all of their automated testing — since the answer is “it depends”, depending on the number of classes and methods written.
  • Duplicated testing effort by test analysts — since the automated tests implemented by developers typically are not visible to the non-developers in the team, the testers usually perform many tests that may already be covered by the developer’s automated tests.

In contrast, some of the advantages of the Behaviour-Driven Development approach to implementing tests include:

  • The team agrees, up-front, on the behaviours to be implemented and afterwards there is no room for a debate about the value of any of the tests;
  • The team decides, up-front, which behaviours are implemented by the developers and which behaviours are performed by the testers — more on this later;
  • The team can more accurately provide estimates to management — since the tests are not dependent on the number of classes and methods coded;
  • There typically are fewer tests and they are less brittle. When a refactoring of the implementation code takes place, there are less refactorings of the test code to perform. Even though there are less tests, there still can be similar test coverage — because overall behaviour is being tested — not individual method functionality; and
  • Test analysts (and everyone) have visibility of all the tests of each component and therefore should not unknowingly duplicate testing effort.

Next » Overview Of The Gherkin Language

Effective Behaviour Specification Descriptions

« Table of Contents »
Previous Chapter « General Tips

The Behaviour Specification Handbook

Effective Behaviour Specification Descriptions

This chapter in The Behaviour Specification Handbook provides tips and recommendations on how to write effective Behaviour Specification Definitions for maximum understanding and maintainability.

  1. Start With Should
  2. Indicate Positive or Negative Behaviour
  3. Indicate Primary or Secondary Behaviour
  4. Unique Within Their Feature File
  5. Unique Without Their Feature File
  6. Follow This Template


Next » Start With Should


Next Chapter » Effective Behaviour Specification Steps

Effective Behaviour Specification Steps

« Table of Contents »
Previous Chapter « Effective Behaviour Specification Descriptions

The Behaviour Specification Handbook

Effective Behaviour Specification Steps

This chapter in The Behaviour Specification Handbook provides tips and recommendations on how to write effective Behaviour Specification steps.

  1. Work Backwards: Then-When-Given
  2. Avoid “I”
  3. Terminology Guidelines
  4. Reuse Steps, If Possible
  5. Understand Technical Tool Constraints
  6. Single When
  7. Guidelines For Examples and Data Tables


Next » Work Backwards: Then-When-Given


Next Chapter » The Implementation Process

Feature Files

« Table of Contents »
Previous « Thoughts On Gauge

The Behaviour Specification Handbook

Behaviour Specifications

Feature Files

A Feature file contains the Behaviour Specifications for a logical grouping of related functionality. I recommend having one feature file for each different software component involved in the same logical grouping of functionality.

File-System Folder Structure

I recommend grouping various feature files as appropriate into different file-system folders that follow a logical hierarchy. Each top-level of the hierarchy could be the name of an architectural capability, domain or whatever similar high-level grouping mechanism or category that makes sense.

Sub-folders can be used for other mid-level logical groupings of behaviour. The names of the sub-folders should include a verb, as after all, we are describing categories of behaviours, and behaviours are described with verbs. The sub-folder’s name could describe the set of processes, actions, behaviours and activities that take place, and always should be in business language — not implementation or system-specific language.

The feature files should exist within the lowest-level sub-folders.

Below is an example of the recommended folder structure:

 1Purchasing (top-level folder, also a known business capability)
 2|
 3|---- ProcessingOrders (mid-level sub-folder, a general category of behaviours)
 4        |
 5        |---- Shopping (low-level sub-folder, a general category of behaviours)
 6                |---- ManageShoppingCart.feature
 7                |---- CalculateShippingCosts.feature
 8                |---- ProcessPayments.feature
 9                |---- PlaceOrder.feature
10        |
11        |---- FulfillingOrders (low-level sub-folder, a general category of behaviours)
12                |---- PickOrderItems.feature
13                |---- ShipOrderItems.feature

Source Control Branches

Different software components may live in different code branches or projects within your source control repository. The feature files for a given software component should live in the same code branch as its component. For consistency reasons, it is helpful for the benefit of the entire team to try to keep the same folder structure for feature files across the various software components, where it makes sense.

I also highly recommend not having white-space characters in a folder or feature file name, as this can cause problems depending on the technology platform or development tools you are using.


Next Page » Feature Names

Feature Names

« Table of Contents »
Previous « Feature Files

The Behaviour Specification Handbook

Behaviour Specifications

Feature Names

At the top of a Gherkin feature file is the feature’s name or title. I recommend naming the feature with a concatenation of the full folder hierarchy and feature file name. I also recommend suffixing the feature name with the type of software component (such as User Interface, Service Layer, etcetera) so that feature files for the same related functionality are clearly discernible by the type of software component that implements them.

The template I find most useful for the name of a feature at the top of a feature file is:

1Feature: [Hierarchy-LogicalGrouping]-[FileName]-[ComponentType]

Here is an example feature name, for a User Interface component:

1Feature: Purchasing-ProcessingOrders-Shopping-ManageShoppingCart-UI

And here is the same example feature, this time for the corresponding component in the service layer:

1Feature: Purchasing-ProcessingOrders-Shopping-ManageShoppingCart-ServiceLayer

Different Feature Files, Same Behaviours

It is often the case that some of the exact same behaviour descriptions and Gherkin can be reused in the different feature files of each software component involved in the same logical grouping of functionality. For example, the feature files for both the User Interface and the back-end service layer involved in the same logical grouping of functionality could have the same behaviour descriptions and Gherkin. The back-end service may have additional behaviours for extra business logic that it alone must perform, but as a starting point, the initial set of behaviours could be the same.

As stated earlier, behaviours must always be considered and understood from within the context of and from the perspective of their software component / feature file. Even though the wording of the behaviour may be the same, the actual meaning and implementation will differ, based upon that context. This is why it is beneficial to suffix the feature name with the type of software component, as it is an important contextual differentiator.


Next » What Is A Behaviour Specification Description?