Follow This Template

« Table of Contents »
Previous « Unique Without Their Feature File

The Behaviour Specification Handbook

Effective Behaviour Specification Descriptions

Follow This Template

The complete format for a Behaviour Specification Description that I have found to be most helpful holistically, for the majority of team members is:

1    [Feature-Context]-[TestTypeAcronym]010 - [Primary/Secondary]/[Positive/Negative] - Should [...]

For example:

  • Purchasing-ProcessingOrders-Shopping-ManageShoppingCart-UI-UT010a - Primary/Positive - Should successfully validate [...]
  • Purchasing-ProcessingOrders-Shopping-ManageShoppingCart-UI-UT010b - Primary/Positive - Should provide a notification of a error when an expected error occurs when validating [...]
  • Purchasing-ProcessingOrders-Shopping-ManageShoppingCart-UI-UT010c - Secondary/Negative - Should provide a notification of a general system error when an unexpected error occurs while validating [...]
  • Purchasing-ProcessingOrders-Shopping-ManageShoppingCart-UI-UT020 - Primary/Positive - Should do something else that is not extremely closely related to the 010 behaviours, since this is 020

Different team members, coming from their individual roles and perspectives, can and will debate the value of all of the information that is being included into the Behaviour Specification Descriptions. From some of their differing backgrounds and individual perspectives, they may be correct. However, Behaviour Specifications are about clear communication to all types of team members, not just some roles and individual perspectives. The inclusion of all the above information in each Behaviour Specification Description makes each behaviour more meaningful to a wider range of team members, and makes each Behaviour Specification more self-contained. This makes life easier for all present and unknown future team members — especially when someone needs to reference a specific behaviour outside of the context of the feature file.

This approach provides the benefit of clearer understanding holistically for the entire team, and that has always, in my experience, trumped the small annoyance of the verbosity of the description. Someone invariably will be cursing if the information is not there and they are the poor soul that now has to find a needle in a haystack. For the little amount of discipline required, just do it, or your own slight variation — it will be worthwhile and will save the team from future pain!


Next Chapter » Effective Behaviour Specification Steps

General Tips

« Table of Contents »
Previous Chapter « The Behaviour Specification Writing Process

The Behaviour Specification Handbook

General Tips

This chapter in The Behaviour Specification Handbook provides general tips for writing effective Behaviour Specifications.

  1. The Software Component Context Is King
  2. Avoid Specifying Internal Technical Implementation Details
  3. Specify Relevant Business Capabilities
  4. Specify Component Interaction Behaviours
  5. Write One Specification For One Behaviour
  6. Use Present Tense
  7. Avoid Generic Verbs
  8. Write In Everyday Business Language
  9. SpecFlow/Cucumber Is Only The Name Of A Tool
  10. Have Different Feature Files For Different User Interfaces


Next » Software Component Context Is King


Next Chapter » Effective Behaviour Specification Descriptions

Guidelines For Examples and Data Tables

« Table of Contents »
Previous « Single When

The Behaviour Specification Handbook

Effective Behaviour Specification Steps

Guidelines For Examples and Data Tables

The most important guideline to remember is to ensure that each Behaviour Specification remains readable, easily understood and worded in everyday business language. Just because Gherkin allows for data tables to be specified, it does not mean that they always should be used. A data table after a step, or an “Examples” table at the end of a scenario has the potential to reduce the readability of a behaviour – so beware!

When using a table, ensure that the type of data specified does not jeopardize the single-purpose focus of that Behaviour Specification. For instance, it is unwise to encode multiple business rules into the table, as each business rule, for the sake of clarity, really should be its own, separate Behaviour Specification. Please note the difference between a “business rule” and individual pieces of logic that when combined may be encompassed within and make a single business rule. Tables are most useful in circumstances to provide examples of key data for specifying a single business rule.

Use general good testing practices and common sense when specifying data in a table:

  • Data that is irrelevant to the behaviour should not be specified;
  • The data specified should not be linked magically to a specific test environment, as the test should be executable in any environment. Use dynamic data for Integration Tests;
  • Data should only exist in a table if it is necessary to illustrate or trigger the conditional logic or branch paths of a business rule;
  • Data generally does not need to be repeated in the table – repeated data that never changes indicates that the behaviour is not written as simply and concisely as it could be; and
  • If possible, abstract the data into business language rather than specifying technical details.

Example Table 1

In this example, there is a manufacturing business where orders for products are taken and processed. In this business there is a software component that accepts an order into the system. A single validation-style business rule in that component could be related to ensuring that a mandatory product code has been provided for each order item, and that the product code is “valid”.

Digging deeper into the technical understanding of this business rule, there are two interesting points here:

  • The mandatory product code, in this case, is a string data type, and thus for it to be “provided”, the value must not be null (“not specified”) and it must not be an empty string with a length of zero characters (“blank”).
  • The word “valid” can sometimes be too general and cover multiple conditions depending on the business context, so be careful. In this case however, it simply means that the product code relates to a real product that is listed in the inventory.

We could thus decompose this business rule into three statements:

  • Should error when an order item has a product code that is not specified;
  • Should error when an order item has a product code that is blank; and
  • Should error when an order item has a product code that does not refer to a listed inventory item.

One could create a Behaviour Specification for each of those statements. However, those statements really refer to internal implementation details about the one, single business rule – that the product code must be valid. This is exactly the type of situation where I recommend using a table.

Below is an example Behaviour Specification for this business rule.

 1@UnitTest
 2Scenario: [Purchasing-ProcessingOrders-Ordering-Service]-010 – Primary/Positive – Should error when an order item has an invalid product code
 3
 4Given an order with an order item where the product code is invalid due to it being <An Invalid Product Code Situation>
 5When the order is submitted for processing
 6Then there is a notification that the product code is invalid
 7
 8Examples:
 9| An Invalid Product Code Situation |
10|-----------------------------------|
11| Not specified                     |
12| Blank                             |
13| Not in the inventory              |

This type of Behaviour Specification is reasonably simple for a developer to implement as a Unit Test.

Please note the language used in the Behaviour Specification – it is obvious, self-explanatory and concise. The description tells you, in natural English, that the behaviour is about invalid product codes. Also note that the information in the Examples table also is in natural English and is quick and easy to understand. A table that requires more than a few seconds to interpret or reverse engineer from actual data values back into business language is generally not a desired table!

Example Table 2

Here is another perfectly valid example Behaviour Specification for a service that performs the functionality of the “AND” logical operator of a calculator. This example is more similar to the type of samples generally found by a quick search, and is an interesting contrast to the previous because of its different nature.

 1@UnitTest
 2Scenario: [Calculations-Service]-010 – Primary/Positive – Should correctly calculate the logical AND of two binary numbers
 3
 4Given the first binary number of <Number1>
 5And the second binary number of <Number2>
 6When the logical AND operator is applied to both binary numbers
 7Then the result is <AND Result>
 8
 9Examples:
10| Value1 | Value2 | AND Result |
11|--------|--------|------------|
12| 0      | 0      | 0          |
13| 0      | 1      | 0          |
14| 1      | 0      | 0          |
15| 1      | 1      | 1          |

Again, the language used in the Behaviour Specification is as natural as possible to the business domain.


Next Chapter » The Implementation Process

Have Different Feature Files For Different User Interfaces

« Table of Contents »
Previous « SpecFlow/Cucumber Is Only The Name Of A Tool

The Behaviour Specification Handbook

General Tips

Have Different Feature Files For Different User Interfaces

How does one specify the various User Interface behaviours for keyboard or voice activation, touch-enabled device taps and mouse clicks?

The short answer is: the software component context is king!

Each different interface should be considered another dimensional axis of the same set of behaviours. In this situation, I recommend different feature files for each different type of User Interface. I suggest one feature file for the voice interface behaviours of this component, a different feature file for the touch-enabled interface behaviours, and another for the mouse-based desktop computer interactions, etcetera. Each feature file would have the exact same set of Behaviour Specifications and step wording. The context – which User Interface type the feature file refers to – conveys the understanding of the User Interface implementation mechanism, and how, for example a button’s click action is triggered.

Again, there is no need in the Behaviour Specification to specify implementation details, and if those details are desired, they should be available in the test run output.

If a team would like to document the fact that all these different User Interface interaction mechanisms are available, then fantastic – but that belongs in a User Interface Guide and not as Behaviour Specifications in a feature file!


Next Chapter » Effective Behaviour Specification Descriptions

Identify Which Developers Will Code Each Behaviour

« Table of Contents »
Previous « The Roles Of Developers and Test Analysts

The Behaviour Specification Handbook

The Implementation Process

Identify Which Developers Will Code Each Behaviour

The Behaviour Specifications are complete, and the team is ready to start the actual coding. At this point in the process, it is useful to have the team agree which developers will do the coding of each behaviour.

I generally suggest that each developer should, to begin with, take a software component / feature file each. This of course depends on the number of software components available to be developed, but this approach generally allows each developer to work with less contention.

The team also will need to pay attention to the dependencies of each software component, and try to develop the most critical, common components first.


Next » Identify Who Will Code The Automation Or Manually Perform Each Test

Identify Who Will Code The Automation Or Manually Perform Each Test

« Table of Contents »
Previous « Identify Which Developers Will Code Each Behaviour

The Behaviour Specification Handbook

The Implementation Process

Identify Who Will Code The Automation Or Manually Perform Each Test

At this point, the team has already decided which developers will code each behaviour, and now they need to decide who will code each automated test, or perform each manual test.

In the scenario where the developers are implementing the automated tests, I have found it can be beneficial for a pair of developers to work together in order to deliver a given software component. The first developer can be writing the code to implement the behaviour, and in parallel — or even beforehand — the second developer can be writing the automated testing code. This can allow each developer to focus on one type of technology and reduce the amount of mental task switching – thus streamlining each individual’s coding.


Next » Code!

Indicate Positive or Negative Behaviour

« Table of Contents »
Previous « Start With Should

The Behaviour Specification Handbook

Effective Behaviour Specification Descriptions

Indicate Positive or Negative Behaviour

All good test suites include both positive and negative tests. Behaviour Specifications are the same in this regard.

Positive Testing should ensure that the functionality under test works as expected, produces expected errors as required, and does not produce unexpected errors.

Negative Testing should ensure that the functionality under test can gracefully handle an unexpected or invalid circumstance that causes the functionality to break.

In my experience, prefixing the Behaviour Specification Description (before the word “Should”) with “Positive” or “Negative” allows everyone reading the Behaviour Specification or test report to quickly and easily understand whether the behaviour is focused on the positive or negative situation.


Next » Indicate Primary or Secondary Behaviour

Indicate Primary or Secondary Behaviour

« Table of Contents »
Previous « Indicate Positive or Negative Behaviour

The Behaviour Specification Handbook

Effective Behaviour Specification Descriptions

Indicate Primary or Secondary Behaviour

A low-level technical design typically identifies the need for some components that are not immediately obvious from the core business requirements. Some software components in a solution may exist purely to enable or support the functionality of other components that are more obviously required. Similarly, even within a component that exists directly to fulfil a core business requirement, some behaviours within that component may exist purely to enable or support other behaviours.

To help team members better understand the solution and design, it can be helpful to distinguish between these two types of behaviours:

  • Primary Behaviours; and
  • Secondary Behaviours.

A Primary Behaviour is a behaviour that has been identified and defined as a direct result of attempting to fulfil a core business requirement. Examples of Primary Behaviours include:

  • Validation logic;
  • Notifications of expected error messages;
  • Business rules (including auditing);
  • Business errors; and
  • Workflow or routing logic.

A Secondary Behaviour, in comparison, is typically a lower-level behaviour required in the solution in order to enable or support the functionality of a Primary Behaviour. These types of behaviours typically are not thought of or identified by business people. A Secondary Behaviour is in no way less important than a Primary Behaviour — in fact, from one perspective, a Secondary Behaviour is more important because a specific Primary Behaviour is dependent upon and cannot function correctly without that Secondary Behaviour. Examples of Secondary Behaviours include:

  • Exception handling;
  • Transaction or data consistency concerns;
  • Data storage and retrieval;
  • Performance concerns; and
  • Logging functionality.

In my experience, including “Primary” or “Secondary” in the Behaviour Specification Description allows everyone reading the Behaviour Specification or test report to quickly and easily understand whether the behaviour exists directly to fulfil a core business requirement or is required due to lower-level, secondary concerns.


Next » Unique Within Their Feature File

Meeting Milestone 1 - Background Context and Requirements Overview

« Table of Contents »
Previous « The Behaviour Specification Writing Meeting

The Behaviour Specification Handbook

The Behaviour Specification Writing Process

Meeting Milestone 1 — Background Context and Requirements Overview

As an introduction to the meeting, please encourage the attendees to ask questions at any time, and ensure that all relevant feedback is recorded.

Start the Behaviour Specification writing meeting with background context about the User Story. It is always useful to set the scene by walking through the business process that leads into this User Story and any other relevant high-level information about the business. (You do have well-defined business processes that you used as part of the requirements analysis effort, don’t you?!)

After the attendees have a high-level understanding of the business process, now dive in and explain the requirements. It is quite useful to create a bullet-point list of all the “core business requirements” and have it visible to the attendees throughout the meeting. This list is very handy during the behaviour identification and describing stage below.


Next » Meeting Milestone 2 — Technical Design Overview

Meeting Milestone 2 - Technical Design Overview

« Table of Contents »
Previous « Meeting Milestone 1 — Background Context and Requirements Overview

The Behaviour Specification Handbook

The Behaviour Specification Writing Process

Meeting Milestone 2 — Technical Design Overview

Now that the attendees have an understanding of the business context and requirements, it is time for a technical representative to present the low-level, initial technical design. Referencing the previously presented requirements, the technical representative should highlight the initially proposed systems and software components, and their relevant interactions.

This is a fantastic opportunity for the entire team (yes, even the business analysts and any other less technically focused people) to learn the technical design and lingo, and also initially challenge the technical design.


Next » Meeting Milestone 3 — Checkpoint