What's Happening In Our Minds?

« Table of Contents »
Previous « Meeting Milestone 3 — Checkpoint

The Behaviour Specification Handbook

The Behaviour Specification Writing Process

What’s Happening In Our Minds?

Throughout all of the above overviews and discussions, each attendee has learned valuable implicit knowledge. Referring back to a previous point, this is the reason why the attendees should be the actual people who will do the development and testing — because throughout this meeting they are being transformed into the experts of this business functionality!

As the team next proceeds to write the behaviours of each software component, multiple team members from different roles and perspectives are mentally testing each behaviour against their understanding of the solution — fantastically optimizing the feedback loop and enabling the team to avoid mistakes and reduce costly, wasteful effort and rework!

The next steps of actually writing the Behaviour Specifications is an important time where the attendees actively engage their mind and further collaborate and communicate. The result of the attendees actively engaging in the process is the growth of their own tacit knowledge and expertise. Again, this is the reason why the attendees should be the developers and testers of this functionality, because they become the experts who can most effectively and efficiently perform the implementation work.


Next » Meeting Milestone 4 — Behaviour Identification

Work Backwards: Then-When-Given

« Table of Contents »
Previous « Effective Behaviour Specification Steps

The Behaviour Specification Handbook

Effective Behaviour Specification Steps

Work Backwards: Then-When-Given

Consider writing the Gherkin steps in reverse order. Write the “Then” steps first, followed by the “When” and finally elaborate on the “Given” steps.

The wording in the “Then” steps (and also some of the other steps) typically overlaps with part of the Behaviour Specification Description that already has been written. Starting with “Then” and copying and pasting the relevant text from the Behaviour Specification Description is a great way to focus on the goal and kick-start the process of specifying that particular behaviour. Sometimes doing this feels too easy, but it is a sound approach — and no one ever suggested that writing the steps has to be difficult!


Next » Avoid “I”

Write In Business Language

« Table of Contents »
Previous « Write In Everyday Business Language

The Behaviour Specification Handbook

General Tips

SpecFlow/Cucumber Is Only The Name Of A Tool

SpecFlow, Cucumber and the others are just tools that facilitate the creation and running of executable behaviour specifications, to be used when a team is focused on using Behaviour-Driven Development to mature their software development practices.

Too many times I have heard team members and managers with a low maturity in and understanding of BDD talk about “the specflows” or “the cucumbers”. Please, no, have some respect! Even though the developers and testers may use those tools, nobody in the team really should be focusing on or mentioning the names of those tools in their everyday conversations about software development. Instead of saying the tool’s name, they should be talking simply about “Behaviour Specifications”, “behaviours”, “specifications”, “specs” or “scenarios”.


Next » Have Different Feature Files For Different User Interfaces

Write In Everyday Business Language

« Table of Contents »
Previous « Avoid Generic Verbs

The Behaviour Specification Handbook

General Tips

Write In Everyday Business Language

A large focus of Behaviour-Driven Development (BDD) is about clear and effective team communication. Not all members of the team have or will have a deep technical understanding. It is in the best interest of the business if everyone is enabled and given the opportunity to understand the logical functionality of each software component.

On a daily basis, the team normally should be communicating with the rest of the business in commonly accepted business terminology. Similarly, the behaviours should be written — as much as possible — in the same accepted style of business language. By doing this, all members of a software development or solution delivery team, including developers, analysts and stakeholders, should be able to understand the Behaviour Specifications.

For instance, say that a business project team engages an internal software development team to develop a subset of a larger solution. The business project team certainly could be interested in reading and understanding the Behaviour Specifications (the test case suite) of the software components that the internal software development team authored. Whether other wider parts of a business would be interested is debatable, and I think that may only apply to businesses with quite a high degree of maturity.

Agree On Business Terminology

The team needs to have a clear understanding about what is commonly accepted business terminology versus technical terminology. In general, communication cannot take place effectively unless agreed protocols are followed. An agreed glossary of business terminology is the basis for an effective communication protocol within a business and is useful reference material — especially for on-boarding new employees.

Such an approach promotes more consistent communication within the solution delivery and support teams — and with wider parts of the business. One tangible, beneficial result of using commonly accepted business language is the minimisation of the costs to train new staff.

Be Professional

Some developers may initially consider working with the Gherkin language and the use of a feature file as a burden. These developers may argue that the usage of the feature file slows them down and that they can much more quickly write automated tests without Gherkin or Behaviour Specifications.

Typically however, such developers are new to the use of Gherkin and have not proceeded past the learning curve. Additionally, some stereotypical technical people can have difficulty in translating technical functionality into common business language for discussion with non-technical people. Because of these reasons, some developers may find they are initially slower in this area, and that can be a cause of personal frustration.

We all need to remember to be professional and look after the best interest of the business. It is in the business’s best interest if the team writes behaviours in their business language, not just for the current set of skills in the team, but for the wide variation of skills that future team members may or may not have. The business language is the lowest common denominator language — not technical terminology.

If the business is primarily product focused or technical in nature, such as one that creates software languages or compilers, then the business language and technical language may be one and the same. By all means, write the behaviours in the business language, which in that case may be quite technical.

Use Natural Language

As a guideline, I highly recommend using the natural language, logical names of artefacts, as opposed to the technical, implementation-specific terminology.

For example, say there is a business service operation for processing credit card payments. In a specification, I recommend writing natural language such as “the service that processes a credit card payment” instead of a more technical implementation name such as “the CreditCardService.ProcessPayment operation”.

Similarly, to refer a particular system in a specification, such as a fictional system named “Insurance Policies 4 Me”, write a natural language, logical name that is appropriate for the business, such as “the insurance policy system”.

Some Technical Terminology Becomes Mainstream

At certain points in time, some terminology that originates from the technical realm does actually make its way into business and everyday, mainstream vernacular. The television and movie industry no doubt have played a huge role in helping to mainstream many technical concepts.

Nothing in the last decade highlights this better than the world of personal and mobile computing. The concept of an “app” or “application” is now common, mainstream vocabulary. From young children to retirees, almost everyone now has access to a mobile phone, tablet or personal computing device, and everyone is familiar with “apps” and an “app store”. Security mechanisms to ensure authorised access to a device — such as user credentials, pin numbers, and swipe patterns — also are now mainstream concepts.

A personally memorable example of this occurred many years ago with my dearly departed mother. One afternoon she came home from a training course at her workplace, and proudly boasted that she had learned how to use their computer system. She then started talking about her “lowgan”. I immediately stopped her and asked what she was talking about — what was this “lowgan”? We had a good laugh together when she said that she and some other staff members didn’t really know who this “lowgan” was, but she knew she had to enter her user name and password when “he” popped up! Of course, between fits of laughter, I quickly explained that it was a “log in”.

What Is Technical Terminology?

Noting that language and commonly accepted vocabulary changes over time, what is technical terminology, and what is not?

That is a good question! The answer is that it depends on each business. What might be considered “technical” in one business, at a specific moment in time, might be common business language right now at another business.

In addition, there are many concepts that began in and are commonly understood in real-life. Many real-life and mathematical concepts have been used as the basis for technical lingo. An example of this is a “queue” of items. A queue is a well understood, real-life concept. Many people stand and wait in queues or first-in-first-out (FIFO) lines at the shopping centre checkout on a regular basis. If a technical team determines that there are messages that need to be queued as part of a solution design, then please say that in the Behaviour Specification, as it is natural everyday language!

Human perception also adds complexity to the discussion. Different businesses, teams and people can have both valid and differing views about how “technical” some “technical terminology” actually is. Every individual has a different perspective and understanding of the world, and their level of tolerance for technical terminology differs.

The Art Of Writing

In the end, finding simple, intuitive and natural words to use when writing a Behaviour Specification sometimes can be thought of as an “art”. There can be a delicate balance between not using language that is too technical or specific, and at the other end of the spectrum, using language that is too generic such that the reader cannot grasp the essence or actual purpose of the behaviour. This balance can be a challenge, especially for novices — but is overcome with an agreed business terminology glossary, some good examples and a little practice.

Tip: It is always helpful to copy the style of existing behaviours that your team agrees are well-written. Take samples of these existing well-written Behaviour Specifications into each behaviour writing meeting and refer to them as necessary. It is often helpful to review these in the meeting to refresh everyone’s memory and help break through any mental blocks.


Next » SpecFlow/Cucumber Is Only The Name Of A Tool

Write One Specification For One Behaviour

« Table of Contents »
Previous « Specify Component Interaction Behaviours

The Behaviour Specification Handbook

General Tips

Write One Specification For One Behaviour

Generally, each Behaviour Specification should be focused on a single behaviour, purpose or business rule. By doing this, each behaviour becomes an independent building block of trusted, tested and verified functionality.

When each single-purpose Behaviour Specification is implemented as an automated test, the process of discovering the root cause of an issue is very quick — there is little analysis required because there is no ambiguity about which behaviour or functionality failed.

A “line of trust” forms out of the understanding that each behaviour is itself tested and verified. When writing each subsequent behaviour, be aware of and use this “line of trust” to your advantage. There is no need to duplicate or re-specify the functionality that is already specified in other Behaviour Specifications.


Next » Use Present Tense

Launch of the BDD Behaviour Specification Handbook!

In the world of Behaviour-Driven Development (BDD), today I am launching The Behaviour Specification Handbook! Please note that this handbook significantly supercedes the two previous blog articles I wrote on the subject - they were the genesis of this work.

Contained in this handbook is more than five years of learnings from practising and coaching BDD on enterprise software development projects. This handbook is my suggested, 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.

I hope the handbook helps you and your team to write better Behaviour Specifications and deliver successful solutions!

Behaviour Specification Writing Methodology - Part 2

Please note, as of August 2015, this article is superseded by the The Behaviour Specification Handbook

In my previous article, Behaviour Specification Writing Methodology - Part 1, I discussed the prerequisites for writing Behaviour Specifications / scenarios. This article elaborates on my tips and suggestions for the next stage - actually writing the Behaviour Specifications.

The Behaviour Specification Writing Meeting

After all the prerequisites have been satisfied (i.e. core business requirements are known and the initial, low-level technical design has been drafted), it is now time to write the Behaviour Specifications. Schedule a Behaviour Specification writing meeting!

Attendees

The attendees of the Behaviour Specification writing meeting should include a holistic cross-section of the 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 Lead/Architect;
  • Business Analysts;
  • Test Analysts; and
  • Developers.

Actual business representatives may of course also attend and can be especially useful if the requirements are not as clear as originally thought coming into this meeting. Assuming however that the requirements are crystal clear, the business representative would only attend predominantly for their own benefit and understanding, or for team building reasons.

Background Context and Requirements Overview

Please encourage the meeting attendees to ask questions at any time, and note all relevant feedback.

Start the Behaviour Specification writing meeting with some background context about the User Story. A walk-through of the business process leading into this User Story and other relevant high-level information about the business is always useful to set the scene.

It is also beneficial at this stage to now explain and walk the attendees through the requirements.

Technical Design Overview

Now have a technical representative walk the attendees through the low-level, draft technical design. Referencing some of the previously mentioned requirements, the technical representative should highlight the initially proposed systems and components and their relevant interactions.

This is a fantastic opportunity for the entire team (yes, even the Business Analysts) to understand the technical design and lingo, and initially challenge the technical design.

Checkpoint

At this stage, let the attendees ask any more relevant questions and note all relevant feedback.

As necessary, evolve the technical design on the spot to cater for any issue that has been identified.

If there are significant issues with the requirements or technical design, then consider whether it is prudent to postpone the rest of this meeting.

What’s Happening In Our Minds?

Throughout all of the above overviews and discussions, each attendee has now learned valuable implicit knowledge. This is the reason why the attendees should be the actual people who will do the development and testing - because throughout this meeting they are being transformed into the experts of this business functionality!

As the team next proceeds to write the behaviours of each component, multiple team members from different roles and perspectives are mentally testing each behaviour against their understanding of the solution - fantastically optimizing the feedback loop and enabling the team to avoid mistakes and reduce costly, wastful effort!

The process of writing the Behaviour Specifications is an important time where the attendees actively engage their mind and further collaborate and communicate. The result of the attendees actively engaging in the process is the growth of their own tacit knowledge and expertise. Again, this is the reason why the attendees should be the developers and testers of this functionality, because they become the experts who can most effectively and efficiently perform the implementation work.

To Gherkin or Not To Gherkin?

The Gherkin language is the most widely used and recognised business-readable domain-specific language (DSL) for specifying behaviours. Behaviours are defined within “Feature” files. Each Behaviour Specification is a “Scenario”, which has a description, and then is further defined as executable steps, with each step beginning with word “Given”, “When”, “Then”, “And” or “But”. Depending on the platform, there are different tools for parsing and executing the Gherkin. For instance, there is Cucumber for Ruby, SpecFlow for .NET, jBehave for Java, Behat for PHP…

The new kid on the street is Gauge. In Gauge, behaviours are defined in “Specification” files that follow the Markdown syntax. Each Behaviour Specification has a heading, description and then is further defined as executable steps.

The main difference between the syntaxes used in Gauge and Gherkin is that the syntax used in Gauge is completely free and open. There is no “Given”, “When”, “Then” restriction like in Gherkin, and this flexibility can be a powerful draw card for some people.

However, with so much flexibility and power, there is the need for great responsibility and consistency - especially in an enterprise. In a medium or larger business or enterprise, consistency in language and style is important. If such a business were to use Gauge, the first thing the business should do, in my opinion, is to create a style guide to promote consistency between teams. And congratulations - now the syntax is restricted - and that flexibility is tamed.

In the end, we may as well have just used Gherkin. Sure, there are other cross-language features in Gauge that may pique your interest, but for my Behaviour Specification writing methodology, I am sticking with Gherkin. The recommendations presented here can apply to the Gauge syntax if you so desire.

Behaviour Specification Writing

Now that the requirements are understood by the team and there is general agreement that sufficient requirements are known and the draft technical design is sound enough, the process of writing the Behaviour Specifications can begin.

This behaviour writing process is best broken down into two phases - indeed, often it is worth working through these phases in different meetings, primarily to allow the attendees to have a rest in between:

  1. Identify and write all the Behaviour Specification descriptions; and
  2. Write the steps that would cause the desired behaviour to manifest.

All members of a software development team, including developers, analysts and stakeholders should be able to understand the Behaviour Specification descriptions and steps - because they should be written in commonly accepted business terminology. On a daily basis, the development team normally should be communicating with the rest of the business using accepted business terminology. Similarly the behaviours should be written in the same accepted business style of language (as much as possible). One result of this approach is the minimisation of the costs to train new staff.

This approach also promotes more consistent communication within the development and support teams - and even to the wider business itself. An example of communicating with a wider part of a business is a project team (the wider part) that engages an internal software development team. The project team certainly could be interested in the documented Behaviour Specifications of a system that the internal software development team authored. Whether other wider parts of a business would be interested is debatable, and I think it may only apply to businesses with quite a high degree of software development maturity.

As an overarching style guideline, I highly recommend that all wording used in a Behaviour Specification should only need to change if there is a change to the core business requirement - and specifically the wording should not need to be changed if there is a change to the implementation.

Finding the right words to use when writing a Behaviour Specification can be thought of sometimes as an “art” due to the delicate balance between not using language that is too technical or specific, and at the other end of the scale, using language that is too generic that the reader cannot grasp the essence or actual purpose of the behaviour. Finding this balance can be a challenge, especially for novices. The best advice I can give is to copy the style of existing behaviours that your team agrees are well-written.

Tip: Take samples of existing well-written Behaviour Specifications into each behaviour writing meeting and refer to them as necessary! It is often helpful to review these in the meeting to refresh everyone’s memory.

Behaviour Identification and Descriptions

Take each system or component that is represented in the low-level technical design, one by one, and answer the following question:

“Within the context, boundary and responsibility of just that component, what are the behaviours that component should perform in order to fulfil all the requirements?”

Generally, each Behaviour Specification should be focussed individually on a single purpose or business rule. By doing this, each behaviour becomes a building block of tested functionality. When writing the next behaviour, you now have a “line of trust” that everything so far is working as specified, and you do not need to re-specify the behaviour or functionality of those building blocks.

End To End Behaviours

In addition to specifying the behaviours for an individual subsystem/component, you should also specify a small number of behaviours of end to end functionality (remember the Test Pyramid!). I suggest these end to end behaviours would be specified in their own feature file, separate from the feature file for the each component, since these behaviours span multiple subsystems/components.

Start With “Should”

Describe each behaviour specification / scenario in a sentence, beginning with the word “Should”.

“Should” at the start of a sentence helps to focus both the author and reader clearly on the actual behaviour. Behaviours are described with verbs. The next word after “Should” is typically a verb… so this helps everyone reading the scenario description to quickly understand the scenario and how it may differ from others.

The behaviour specifications are both living, executable documentation as well as being classified as test assets. The behaviours also are the specification that developers should use when they write code. The only code that should be written by developers is code to satisfy a behaviour specification. No behaviour specification - no code. Importantly, behaviour specifications are NOT part of a formal, legal requirements document.

Each behaviour specification / scenario description is similar to a description of a system’s capability. A system’s capability is not described in terms of “it must/shall/will do XYZ” - that is how a “requirement” might be worded. Behaviour specifications are determined after the business requirements have been identified and agreed upon by stakeholders.

The scenario description is a specification of a system’s expected behaviour - how the system should behave, based on all current knowledge and understanding. Dan North, the originator of BDD, in Introducing BDD eloquently describes more about the usage of 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.”

Use Present Tense

The scenario description makes more logical sense when written in the present tense, because it is the describing the most up-to-date, current, at the present time, expected behaviour.

Avoid Generic Verbs

Avoid the word “handle” or any other verb that is generic and hides the actual behaviour.

For instance, let us pretend that someone wrote the scenario description: “Should handle the situation when the total amount is not equal to the sum of all item amounts”.

The above scenario description has both positive and negative points. On the positive side, the “when” part is descriptive and is an easily understandable, differentiating condition for the scenario. On the negative side however, “handle” is not actually describing the behaviour that occurs under in that situation. What is actually meant by “handle”?

A better alternative is to be more specific about the behaviour. For instance, “Should error when the total amount is not equal to the sum of all item amounts”. Using “error” as a verb instead of “handle” clearly describes the actual type of behaviour that should be performed.

Positive and Negative Behaviours

All good test suites cover both positive / happy path and negative / sad path scenarios. Behaviour specifications are the same.

In my experience, prefixing the scenario description (even before “Should”) with “Positive - " or “Negative - " allows someone reading the behaviour specification or test report to quickly and clearly determine whether the behaviour is focussed on the happy or sad path.

Primary / Business and Secondary / System Behaviours

It can be useful for the purpose of general understanding to distinguish between two different types of behaviours:

  • Primary / Business Behaviours; and
  • Secondary / System Behaviours.

A Primary / Business-based Behaviour is a behaviour that has been defined as a direct result of trying to fulfil a core business requirement.

A Secondary / System-based Behaviour alternatively is a lower-level behaviour needed by a system in order to enable or support the functionality of a Primary / Business Behaviour. A Secondary Behaviour is in no way less important than a Primary Behaviour - in fact, from one perspective, one can think that a Secondary Behaviour is more important because a specific Primary Behaviour is dependent upon and cannot function correctly without the Secondary Behaviour.

Examples of Secondary / System Behaviours include:

  • Exception handling
  • Transaction concerns
  • Data storage and retrieval
  • Performance concerns
  • Auditing functionality

Unique Identifiers for Scenarios

When developers write new tests, modify existing tests and/or then need to run tests, it can be very useful to have a mechanism to easily identify and pick a specific scenario/test out of a list of many scenarios/tests. For instance, when developers are using their favourite IDE’s Test Runner, if they want to find a specific scenario/test to run (even after using search or filtering on @tags), a unique identifier for each scenario can really help a human to visually find a specific scenario and select it more quickly.

I recommend including an incrementing number into each scenario description, with the number starting at one in each feature file.

In addition, prepending the feature name (or a shortened, unique version of it) helps to make a behaviour specification uniquely identifiable across multiple feature files.

Including all of the above information in each behaviour specification description makes life for all team members significantly easier when someone needs to reference a specific scenario in a communication, or navigate through a list of behaviours outside of the context of a feature file. For the small amount of discipline required, you will be cursing yourself and other team members if it isn’t done and if you are the poor soul that now has to find a needle in a haystack. Just do it - it’ll be worth it!

The template I find most useful for a scenario description is:

1[FeatureName]-[Primary/Secondary]-01 - [Positive/Negative] - Should blah.

I acknowledge that at times this can become wordy, but in my experience the benefits of clarity with this approach have always trumped that small annoyance.

Feature Files

Zooming out from scenario descriptions within a feature file, let us now focus on other aspects related to the feature file.

File-System Folder Structure

I recommend grouping various feature files as appropriate into different file-system folders that follow a logical hierarchy. The top level of the hierarchy could be the name of an architectural capability or domain (a high-level grouping mechanism or category).

Subfolders could then be used for other logical groupings that make sense, and their names should include a verb (we are after all describing categories of behaviours). The subfolder / behaviour category name may describe the set of processes, actions, behaviour and activities that take place, and should be in business language - not implementation or system specific language.

Within the lowest-level subfolder are the feature files.

Below is an example folder structure:

 1Purchasing (top-level folder, also the name of a domain)
 2|
 3|---- ProcessingOrders (subfolder, a general category of behaviours)
 4        |
 5        |---- Shopping (subfolder, a general category of behaviours)
 6                |---- ManageShoppingCart.feature
 7                |---- CalculateShippingCosts.feature
 8                |---- ProcessPayments.feature
 9                |---- PlaceOrder.feature
10        |
11        |---- FulfillingOrders (subfolder, a general category of behaviours)
12                |---- PickOrderItems.feature
13                |---- ShipOrderItems.feature

The feature files for different subsystems typically will live in different code branches or projects within your source control repository. For consistency reasons, use the same folder structure for feature files across subsystems.

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

Feature Name

At the top of a feature file is the feature name. I recommend making the folder hierarchy and grouping names part of the feature file’s feature name value.

Each behaviour specification within a feature file is written from the context of a system, subsystem or component. Including the name of that subsystem or component in the description is also very using information, for the sake of clarity. Trickily, you may find that you have the exact same behaviour description and Gherkin in more than one component (for example, in both the User Interface and the back-end service layer), but the behaviour actually has a slightly different meaning in each because it must be understood and considered from within the context and perspective of that subsystem/component.

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

1Feature: [Hierarchy-LogicalGrouping]-[FileName]-[Subsystem/Component]

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 back-end of a system:

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

In this example above, “Purchasing-ProcessingOrders-Shopping-ManageShoppingCart-ServiceLayer” is the “feature name” that you would include at the start of each behaviour specification description.


In my next article, I will discuss tips for writing the actual Given/When/Then steps of the Gherkin and about implementing the behaviours as automated tests.

Behaviour Specification Writing Methodology - Part 1

Please note, as of August 2015, this article is superseded by the The Behaviour Specification Handbook

[Updated in April 2015]

Overview

As a long-time advocate of Behaviour-Driven Development (BDD), and being the technical lead and coach of BDD enterprise software development teams for more than 5 years, I have tried many different variations of the process of BDD and the writing and implementation of scenarios. The following is my suggested, 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.

Why BDD?

There are many articles that discuss the beginnings and benefits of BDD, so instead repeating similar information, here are some good starting materials:

Prerequisites

There are two important prerequisite inputs to a Behaviour Specification writing session - the requirements and an initial low-level technical design. I cannot stress enough how important these prerequisites are to hosting a successful Behaviour Specification writing session!

Requirement Analysis Complete

Before your team meets to determine the Behaviour Specifications (typically for a User Story, if your team is following an Agile methodology), ensure that the requirements analysis is as complete as possible. The nemesis of a Behaviour Specification writing session is unknown, unclear or incomplete requirements. Unclear requirements are the primary cause of elongated discussions, frustration and confusion in a Behaviour Specification writing meeting.

During the behaviour writing meeting, if missing requirements are identified, I recommend that you simply make a note of them for later and carry on - if possible. On the other hand, if there is a critical requirement missing, it is wiser to postpone the meeting until the relevant details of the requirement can be determined.

If a team ever walks away from a Behaviour Specification writing session exhausted or thinking that the process is difficult, I can almost guarantee that there was a lack of requirements analysis performed before the meeting. The requirements gathering, analysis and clarification is the difficult work that requires and causes the most discussion, time, effort and agreement. Requirements analysis is thus defined as a prerequisite that should remain a very separate process from behaviour writing.

I have witnessed many Behaviour Specification writing sessions turn into requirements analysis workshops. This in itself is not a bad thing - indeed the Behaviour Specification writing meeting has just succeeded in facilitating, identifying and initiating other important discussions. However, if this happens in your meetings, please be careful to clearly communicate to your team that the Behaviour Specifications have been postponed and the team instead is now performing more requirements analysis. If your boss thinks the team has been “doing Behaviour Specifications” for days with none of the expected outputs produced because all the effort has been requirements analysis, then your boss is not receiving accurate information for tracking and planning purposes. It is unfair to tarnish the name of and blame the process of BDD due to an unfulfilled prerequisite. Additionally, it is counter-productive for stakeholders to start questioning the process of BDD because they incorrectly heard that BDD takes a long time and is difficult - when the culprit really was requirements analysis.

Core Business Requirements

There are different types and ways of describing requirements. For the purpose of the Behaviour Specification writing meeting, it is most useful to have the “core business requirements” understood and documented before the behaviour writing meeting.

A “core business requirement” has a clear purpose and business value, and it explicitly does not contain a description or specification of the implementation details.

If a “requirement” includes implementation detail, then there is the awkward situation where non-technical business colleagues are effectively dictating the implementation design to the technical experts. The technical folk however may think of a better implementation option, if they were empowered and given the opportunity.

Sometimes the “core” requirements are already known, but many times the author of a requirement has innocently encoded implementation-specific details within the requirement. A common example is with User Interface requirements. The User Interface requirement may, for instance, specify the need for a new textbox on a screen. That however is not a “core business requirement” because both “textbox” and “screen” are implementation details.

It is more beneficial to take these implementation-specific requirements and convert them back to “core business requirements”. The “5 Whys” principle can be used to find the “core” or root requirement. By iteratively asking “Why?” or “What is the real underlying business need for doing XYZ?” the “core business requirement” can be uncovered.

Below is a contrived example.

Let’s assume that the documented requirement is: “Display a new textbox on screen XYZ so we can enter data for ABC”.

Why?
“Because we want to enter data for ABC and screen XYZ has related stuff on it.”

Why do you need the data for ABC?
“We need that data for ABC to calculate MNOP.”

Why do you need to calculate MNOP?
“To correctly invoice the customer.”

With this understanding we can now state that the “core business requirement” is: “To receive information about ABC so that the customer can be invoiced correctly”.

It is this type of business language that I highly recommend be used in the Behaviour Specifications / scenarios - not implementation-specific language about a textbox!

I highly recommend that, as overarching style guideline, all wording that is used in a Behaviour Specification should only need to change if there is a change to the “core business requirement” - and should not need to be changed if there is a change to the technical implementation. If you follow this recommendation, your Behaviour Specifications will live and stand strong through the passage of time.

Draft Low-Level Technical Design Complete

After sufficient requirements have been gathered, the solution/technical architects, designers and gurus in the team should have met, discussed and sketched out an initial, draft version of a low-level technical design that identifies the likely systems and components that will be involved in the story.

During the Behaviour Specification writing meeting, the team will focus on defining the behaviours of each of the components that were identified in this low-level technical design.


In Behaviour Specification Writing Methodology - Part 2, I discuss how to successfully run a Behaviour Specification writing meeting.

Program Specification Through the Mechanism of Automated Tests

My previous findings regarding the testing of public methods versus private methods opened the door to allow me to better understand that the mindset of a developer performing unit “testing” is different from the mindset of a developer “specifying program behaviour through the mechanism of automated test methods”. The difference is subtle but important.

In the concept and terminology of Behaviour-Driven Development, Design, Analysis and Programming, the resulting program code is simply an implementation of previously specified behaviours. Those said behaviours are initially defined at the business level via the process of requirements gathering and specification, and can be expressed in the business’s language as a set of scenarios and stories. These requirements can then be further analysed and broken down into logical and physical program specifications.

Regardless of whether a test-first approach to development is taken, by the end of the construction task, there should be a set of test cases (automatic and/or manual) that were successfully executed and that covers all of the logic specified in the program specification. In other words, by the end of the construction task, the developer has verified that the program behaves as specified.

Typically a program’s specification is written in a document somewhere which is divorced from the location of the actual code - so great discipline and effort is required in order to keep the specification and code in synch over time. Depending on the company and financial constraints of the project, this may not be feasible.

However, what if we could remove this boundary between the document and the code?

Automated test cases serve a number of useful purposes, including:

  • Behaviour verification;
  • Acting as a “safety net” for refactoring code;
  • Regression testing;
  • Professional evidence that one’s own code actually does what one has said it does; and
  • Acting as sample code for other developers so they can see how to use one’s code.

What if the automated test assets were the actual living program specification that is verified through the mechanism of test methods?

This concept has been recognised before, and the libraries JBehave, RSpec, NBehave and NSpec have been the result. While I honour the efforts that have gone into those libraries and the ground-breaking concepts, I do not necessarily like the usage of them.

In fact, all I want right now is to be able to express my specifications in my MSTest classes without the need for a different test runner or the need for another testing framework. In addition, I want other team members to easily grasp the concept and quickly up-skill without too much disruption.

While a DSL might be more ideal under these circumstances, I write my automated test assets in the C# language. Working within that constraint, I want to express the program specification in test code. With special note to the agreeable BDD concept that "Test method names should be sentences", I devised the following structure for expressing program specifications as automated test methods.

 1namespace [MyCompany].[MyAssembly].BehaviourTests.[MySystemUnderSpecification]Spec
 2{
 3    public class [MyPublicMethodUnderSpecification]Spec
 4    {
 5        [TestClass]
 6        public class Scenario[WithDescriptiveName]
 7        {
 8            [TestMethod]
 9            public void When[MoreScenarioDetails]Should[Blah]
10            {
11                // Test code here
12            }
13
14            [TestMethod]
15            public void When[AnotherSubScenario]Should[Blah]
16            {
17                // Test code here
18            }
19        }
20    }
21}

This structure allows for the naming of the public method that is under specification (the parent class name), a general scenario with a description of the context or given setup required (the nested MSTest class name), followed by the test method names which further narrow the scenario and provide descriptive details of the expected behaviour.

The test names look neat in the Test View in Visual Studio (when the Full Classname column is visible), and are readable just like their corresponding stories.

The full class name in this instance would look like:

1[MyCompany].[MyAssembly].BehaviourTests.[MySystemUnderSpecification]Spec.[MyPublicMethodUnderSpecification]Spec+Scenario[WithDescriptiveName]

With automated spec/test assets/classes structured in this fashion, instead of developers performing unit “testing”, developers can instead embrace the mindset of “specifying program behaviour through the mechanism of automated test methods”. In turn, developers should be more focused on their tasks and it should also lead to higher quality code bases.

Oh, and I haven’t even mentioned how much easier it would be for a developer new to a project to learn and understand the code base by looking at the test view and reading all the scenarios that have been specified and coded…

If you wanted an even better way to define your program specifications and test assets, then I highly recommend SpecFlow.

Showdown: Testing Private Methods vs Public Methods

The concept of testing private methods has been debated by many people, and up until now I have been happy to sit on the fence.

However, recently I have been looking at simplifying and optimising automated testing code. As part of that process, I created a small sample application with one public service operation method that calls a number of private methods.

In order to answer the question about whether there are worthwhile advantages to testing private methods, I decided to do a shoot-out of automated testing code. Here was the line up:

  • All the test code required to thoroughly test the sample application by testing both private and public methods; and
  • All the test code required to thoroughly test the sample application by testing just the public methods.

The result was conclusive: in order to thoroughly test the sample application, less test cases were required and significantly less automated testing code was required when just explicitly testing the public methods (and implicitly testing the logic in private methods).

Here is a summary of my findings.

  • Less test cases were required because test cases for the logic contained within the private methods overlapped with test cases that were still required in order to thoroughly test the public methods;
  • The private methods were still thoroughly tested implicitly through the test cases for the public methods; and
  • The resulting test code was less brittle so developers can more freely refactor the application code without easily breaking the test code.

Don’t believe me? Perform a similar exercise for yourself!