Separate Implementation Of Unit Test Steps From Integration Test Steps

« Table of Contents »
Previous « Code!

The Behaviour Specification Handbook

The Implementation Process

Separate Implementation Of Unit Test Steps From Integration Test Steps

When implementing the automated tests, it is better to separate all the implementation steps of Unit Tests from the implementation of Integration Test steps, as having the code for both types of steps in the same code file can quickly become confusing. If you imagine a code file that mixes the concepts of mock objects with real calls to actual implementation, you can imagine the type of confusion that could ensue. For everyone’s benefit, please keep them in separate files and classes!

I recommend a file naming convention of “[FeatureFileName]UnitSteps” for the Unit Test step implementation, and “[FeatureFileName]IntegrationSteps” for the Integration Test step implementation. With SpecFlow, it is dead simple to apply a “Scope” attribute to each different class, so that the code in that class is scoped only to scenarios that have a “@UnitTest” or “@IntegrationTest” tag.


Next » Review Test Outputs

Single When

« Table of Contents »
Previous « Understand Technical Tool Constraints

The Behaviour Specification Handbook

Effective Behaviour Specification Steps

Single When

A single “When” statement helps both the reader and tester to focus on the specific, single-purpose behaviour under specification.

If you feel tempted to have an “And” or “But” step that immediately follows the “When” step, then consider moving some of that behaviour up into the “Given” section. Part of what you are trying to specify is likely to be more closely related to the initial conditions that are required to be in place to manifest the behaviour, rather than the specific action that triggers the behaviour.

On the other hand, in the case of specifying something that happens in parallel or concurrently, it might be perfectly valid to have an “And” or “But” step after “When”.

If you are tempted to have a step that contains the word or, then consider whether the Behaviour Specification should be split into two separate Behaviour Specifications that each are better focused on having a single purpose, or whether a table is appropriate.

Given” and “Then” steps with multiple “And” or “But” steps are perfectly fine and common – just ensure it makes sense and is appropriate.


Next » Guidelines For Examples and Data Tables

Software Component Context Is King

« Table of Contents »
Previous « General Tips

The Behaviour Specification Handbook

General Tips

The Software Component Context Is King

When identifying, reading or writing Behaviour Specifications, the context (knowing which software component within the solution is being specified) is the most important thing to understand. It is essential to have a clear understanding of the boundary and responsibility of each software component, otherwise the Behaviour Specifications cannot be correctly understood. This is one reason why the low-level technical design is an important prerequisite.

Be aware of and careful not to start specifying and mixing the behaviours of other components into the behaviours of the current one being defined. There lies the path of complexity and confusion! If you smell that you might be going off-track, go back to and revisit the question — “within the context, boundary and responsibility of just this component…".


Next » Avoid Specifying Internal Technical Implementation Details

Specify Component Interaction Behaviours

« Table of Contents »
Previous « Specify Relevant Business Capabilities

The Behaviour Specification Handbook

General Tips

Specify Component Interaction Behaviours

A Component Interaction Behaviour specifies the public knowledge ways in which other components can interact with the component being specified. These types of behaviours can be thought of as representing public endpoints and describing service contracts. Importantly, Component Interaction Behaviours do not describe internal-only, technical details of a component.

Component Interaction Behaviours — An Example

In this example, say that there is a requirement to develop a business service for processing a change to a customer’s postal address. Importantly, this functionality must be available to any application within the business as a standards-compliant Web Service call. In addition, this same functionality must also be invokable inside the business via a message subscription mechanism, for instance, where there is a well-known, specific type of message published to a message bus. The business has identified and defined a business event message for postal address changes that can be published to the message bus.

There should be two Component Interaction Behaviour Specifications defined in this situation — one for each different and public knowledge way in which other components may interact with this component. The Behaviour Specification Descriptions for this component thus could be:

  1. Positive — Should be exposed publicly as a standards-compliant Web Service; and
  2. Positive — Should be invokable when there is a business event about changes to a customer’s postal address.

The term “Web Service” is acceptable terminology in this case because:

  • it is the public knowledge mechanism by which other components may interact with it — this is not an internal only implementation detail; and
  • “Web Service” is a modern, accepted term in the business’s language glossary.


Next » Write One Specification For One Behaviour

Specify Relevant Business Capabilities

« Table of Contents »
Previous « Avoid Internal Technical Implementation Details

The Behaviour Specification Handbook

General Tips

Specify Relevant Business Capabilities

You may have noticed that the example descriptions in What Is A Behaviour Specification Description? explicitly specify the usage of an “address validation service”. In that example, an “address validation service” is a well-known, documented capability that exists within the business. The example descriptions are subtly referring to the logical capability that exists within the business — a service to validate an address — and not the physical, technical implementation of the service, nor the specific technical name of that physical service.


Next » Specify Component Interaction Behaviours

Start With Should

« Table of Contents »
Previous « Effective Behaviour Specification Descriptions

The Behaviour Specification Handbook

Effective Behaviour Specification Descriptions

Start Behaviour Descriptions With “Should”

In order to write an effective Behaviour Specification Description, describe each behaviour in a sentence, beginning with the word “Should”.

The word “Should” at the beginning of a sentence helps to focus both the author and reader on the actual intent of the behaviour. In the English language, behaviours generally are described with verbs. The next set of words grammatically after “Should” typically is a verb or adverb. By starting with “Should”, the structure of the English language is forcing the optimisation of the descriptions so that we can immediately focus on the intent of the actual behaviour and more quickly understand how it may differ from other behaviours.

A template format for the recommended wording of a Behaviour Specification Description is:

1    Should [action] when [criteria]

The first part of the description is the action to perform, and the second part is the criteria for the action to occur.

For example:

1    Should calculate the invoice amount when an order item is added to an order

This description is clear and intention-revealing about the behaviour. A reader immediately knows and understands that the behaviour is to “calculate the invoice amount”, and the criteria for this occurring is “when an order item is added to an order”.

Applying a standard such as beginning Behaviour Specification Descriptions with the word “Should” helps teams to write more useful and intention-revealing descriptions and naturally fall into the “pit of success”.

Different From A Test Case

A Behaviour Specification Description is subtly different from a description of a Test Case. A traditionally written description of a Test Case is authored from a different perspective that typically aims to summarise the scenario and steps that are taken.

For example, a contrasting traditional Test Case description for the example behaviour above would typically be:

1    Adding an order item

Hopefully you can appreciate the subtle differences between Behaviour Specification Descriptions and Test Case descriptions. The description of the Test Case is often shorter and at a higher summary level.

As has been stated previously in this handbook, requirements are a prerequisite to the identification and writing of Behaviour Specifications.

The Internet Engineering Task Force (IETF) identifies an Internet Best Current Practice (BCP) of “Key words for use in Requests for Comments (RFCs) to Indicate Requirement Levels” - BCP 14 / RFC 2119. This document defines a number of key words as they are to be interpreted in IETF documents.

Of particular note is their definition of word “SHOULD”, meaning that:

"there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.“

I acknowledge that a pedantic reader of a Behaviour Specification Description could choose to interpret “Should do XYZ always” in English as “it should do XYZ always, BUT because you said the word ‘should’, it does not always have to… and therefore there is space for unintended behaviour”. This same type of reader would suggest tightening the terminology in order to make it completely unambiguous and fit for a formally signed business or legal contract — by prefixing the description with the word “Must”, “Shall” or “Will” instead of “Should”.

Behaviour Specifications however, are not part of a formal business contract (such as a requirements document) that requires legally precise wording and change management. Behaviour Specifications are only as-built, living documentation and test assets, and using the word “Should” is perfectly acceptable. There is therefore no need to be concerned about the IETF definition and its irrelevance to Behaviour Specifications.

The Subtle Aspect of “Should”

In case you need any more convincing, Dan North, the originator of BDD, in Introducing BDD, eloquently adds more weight to the argument for using the word “Should”:

"A more subtle aspect of the word ‘should’ becomes apparent when compared with the more formal alternatives of ‘will’ or ‘shall’. ‘Should’ implicitly allows you to challenge the premise of the test: “Should it? Really?” This makes it easier to decide whether a test is failing due to a bug you have introduced or simply because your previous assumptions about the system’s behaviour are now incorrect.“


Next » Indicate Positive or Negative Behaviour

Terminology Guidelines

« Table of Contents »
Previous « Avoid “I”

The Behaviour Specification Handbook

Effective Behaviour Specification Steps

Terminology Guidelines

As previously discussed, it is best to avoid the usage of the word “I”. In addition, it is best to avoid the following list of User Interface-focused words, as they indicate and represent implementation details that are unnecessary and should be avoided in Behaviour Specifications.

The list of User Interface words to avoid includes, but is not limited to: “show”, “view”, “see”, “hear”, “screen”, “page”, “button”, “click”, “tap”, and “navigate”.

Many computer programming languages have the concept of a “null” value. A variable with a “string” data type typically can have a value of “null” or could contain an empty string that has a length of zero characters. Following the guideline to use everyday natural language, I recommend using the terminology “not specified” instead of the word “null”, and “blank value” instead of “empty string”.

I also recommend using the words “error” and/or “notification” to specify behaviours related to when an “exception” occurs in a program. An “exception” is a technical programming concept and is not typical business vocabulary. If the business does regularly refer to business process exceptions, then care must be taken to ensure everyone in the team has a clear understanding of the meaning and how it differs from a technical exception.


Next » Reuse Steps, If Possible

The Behaviour Specification Handbook

The Behaviour Specification Handbook

Overview

As a long-time advocate of Behaviour-Driven Development (BDD) and having been a technical lead and coach of BDD enterprise software development teams since 2010, I have tried many different variations of the process of BDD and the writing and implementation of Behaviour Specifications.

This handbook is my suggested practical, prescriptive methodology for writing Behaviour Specifications (also known as ‘scenarios’ in the Gherkin language), including tips and suggestions that have repeatedly proven to me to be worthwhile practices in both small and large-scale solutions.

I hope they help you and your team to write better Behaviour Specifications and deliver successful solutions!

Table of Contents

Chapter 1: Background

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

Chapter 2: Behaviour Specifications

  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?

Chapter 3: The Behaviour Specification Writing Process

  1. Prerequisites
  2. The Behaviour Specification Writing Meeting
  3. Meeting Milestone 1 — Background Context and Requirements Overview
  4. Meeting Milestone 2 — Technical Design Overview
  5. Meeting Milestone 3 — Checkpoint
  6. What’s Happening In Our Minds?
  7. Meeting Milestone 4 — Behaviour Identification
  8. Meeting Milestone 5 — Step Writing
  9. Meeting Milestone 6 — Determine Test Types
  10. About End-To-End Behaviours
  11. About Outsourcing Delivery

Chapter 4: General Tips

  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

Chapter 5: Effective Behaviour Specification Descriptions

  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

Chapter 6: 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

Chapter 7: The Implementation Process

  1. Behaviour Specifications Before Implementation
  2. The Roles of Developers and Test Analysts
  3. Identify Which Developers Will Code Each Behaviour
  4. Identify Who Will Code The Automation Or Manually Perform Each Test
  5. Code!
  6. Separate Implementation of Unit Test Steps From Integration Test Steps
  7. Review Test Outputs

The Behaviour Specification Writing Meeting

« Table of Contents »
Previous « Prerequisites

The Behaviour Specification Handbook

The Behaviour Specification Writing Process

The Behaviour Specification Writing Meeting

After all the previously described prerequisites have been satisfied (i.e. all the “core business requirements” are known and the initial, low-level technical design is understood), it is now time to identify and write the Behaviour Specifications — so go and schedule a Behaviour Specification writing meeting!

Meeting Attendees

You might be wondering about who to invite to this session?

The attendees of the Behaviour Specification writing meeting should include a holistic cross-section of the solution development team, including all the actual people who will be developing and testing the given functionality. I will come back to this point later.

The types of roles that should attend the meeting include:

  • Technical Architect;
  • Technical/Developer Lead;
  • Business Analysts;
  • Test Analysts; and
  • Developers.

Actual business representatives are welcome to attend and are especially useful if the requirements need further clarification. Assuming however that the requirements are reasonably clear, the business representative would only attend predominantly for their own benefit and understanding, or for team building reasons.


Next » Meeting Milestone 1 — Background Context and Requirements Overview

The Behaviour Specification Writing Process

« Table of Contents »
Previous Chapter « Behaviour Specifications

The Behaviour Specification Handbook

The Behaviour Specification Writing Process

This chapter in The Behaviour Specification Handbook discusses the prerequisites and procedure involved in identifying and writing Behaviour Specifications, and how to effectively host the Behaviour Specification writing meeting.

  1. Prerequisites
  2. The Behaviour Specification Writing Meeting
  3. Meeting Milestone 1 — Background Context and Requirements Overview
  4. Meeting Milestone 2 — Technical Design Overview
  5. Meeting Milestone 3 — Checkpoint
  6. What’s Happening In Our Minds?
  7. Meeting Milestone 4 — Behaviour Identification
  8. Meeting Milestone 5 — Step Writing
  9. Meeting Milestone 6 — Determine Test Types
  10. About End-To-End Behaviours
  11. About Outsourcing Delivery


Next » Prerequisites


Next Chapter » General Tips