Friday 7 November 2008

RSpec's Scenario Runner is dead - Long Live Cucumber!

Recently when browsing RSpec's homepage I noticed the bold (in the markup sense) announcement that RSpec's scenario runner has been deprecated in favour of Aslak Hellesøy's Cucumber. I have always been a fan of RSpec's scenario runner and love the plain text story support. I therefore felt compelled to see what Cucumber has to offer and I am pleased to report that it's wonderful.

First Taste of Cucumber

Having previously used RSpec's scenario runner to provide automated acceptance scenarios for a Ruby implementation of the Game of Life, I was keen to see how easy it was to migrate to Cucumber.

Cucumber can be installed with the following command:

gem install cucumber

Feature Injection

Cucumber is built around features rather than stories and recommends the Feature Injection template for describing features.


In order to [achieve value]
As a [role]
I need [feature].

I therefore revisited the create a cell story (originally found in the examples provided in the RSpec code base) and rephrased the requirement using the Feature Injection template.

Story Format


Story: Cell Creation

As a game producer
I want to create a cell
So that I can set the initial game state

Scenario:
...

Feature Injection Format


Feature: Cell Creation

In order to set the initial game state
As a game player
I need to be able to create live cells.

Scenario: Empty Grid

Given a 3 x 3 game
Then the grid should look like
"...
...
..."

Scenario: Create a single cell

Given a 3 x 3 game
When I create a cell at 1, 1
Then the grid should look like
"...
.X.
..."

Convention over Configuration

Cucumber applies a healthy dose of convention over configuration to provide a scenario runner that runs out of the box. The convention is to keep textual descriptions of features, using a .feature extension, in a features directory. Scenario steps are mapped to application code using Ruby. Step classes live in a steps directory as a child of the features directory.

For example:

   /features
/steps
game_of_life_steps.rb
create-a-cell.feature

When following the prescribed directory structure, scenarios can be executed with the following command:

       rake features

Pending Steps

Initially my game_of_life_steps.rb file did not define any steps. When executing the scenarios for the create cell feature Cucumber kindly told me which steps I needed to provide and even provided suggested implementations. This feature made me smile and was clearly developed in response to the question; how can I reduce the effort required to implement steps?

       10 steps pending

You can use these snippets to implement pending steps:

Given /^a 3 x 3 game$/ do
end

Then /^the grid should look like$/ do
end

When /^I create a cell at 1, 1$/ do
end

When /^I create a cell at 0, 0$/ do
end

When /^I create a cell at 0, 1$/ do
end

When /^I create a cell at 2, 2$/ do
end

Implementing Steps

Textual scenarios are mapped to code using a simple DSL that allows step patterns to be associated with the following step keywords: Given, When, Then. Each keyword accepts a Ruby block that will be executed when a step pattern is matched against an actual scenario step.

Steps can be parameterised using regular expressions, for example:

require "spec"

require "domain/game"
require "view/string_game_renderer"

Given /a (\d) x (\d) game/ do |x, y|
@game = Game.create(x.to_i, y.to_i)
end

When /I create a cell at (\d), (\d)/ do |x, y|
@game.create_cell_at(x.to_i, y.to_i)
end

Then /the grid should look like/ do |grid|
StringGameRenderer.new(@game).render.should eql(grid)
end

Alternatively, steps can be represented as strings using the dollar symbol to prefix a parameter.

For example:

 require "spec"

require "domain/game"
require "view/string_game_renderer"

Given "a $x x $y game" do |x, y|
@game = Game.create(x.to_i, y.to_i)
end

When "I create a cell at $x, $y" do |x, y|
@game.create_cell_at(x.to_i, y.to_i)
end

Then "the grid should look like$" do |grid|
StringGameRenderer.new(@game).render.should eql(grid)
end

Migrating away from Rspec's Story Runner

Using RSpec's story runner I used the following approach to execute my scenarios:

  1. GameOfLifeSteps class extending Spec::Story::StepGroup
  2. GameOfLifeStoryRunner class delegating to Spec::Story::Runner::PlainTextStoryRunner configured with the GameOfLifeSteps
  3. Story classes for each story that delegate to the GameOfLifeStoryRunner passing the filename of the story to execute
  4. A Rake task to execute all of my stories

At the time this did not seem too unreasonable although there was a significant learning curve figuring out how everything was configured. Cucumber solves the configuration problem using convention. Developers need to provide step definitions and Cucumber will handle the rest.

Migrating to Cucumber was largely an exercise in deleting code that was no longer required. The conversion from RSpec step definitions to Cucumber was painless as they are very similar.

Example RSpec Step Definition

require'spec/story'
require "spec"

require "domain/game"
require "view/string_game_renderer"

class GameOfLifeSteps < Spec::Story::StepGroup

steps do |define|

define.given("a $x x $y game") do |x, y|
@game = Game.create(x.to_i, y.to_i)
end

define.when("I create a cell at $x, $y") do |x, y|
@game.create_cell_at(x.to_i, y.to_i)
end

define.then("the grid should look like $grid") do |grid|
StringGameRenderer.new(@game).render.should eql(grid)
end
end
end

Readers will immediately appreciate how easy it is to convert from RSpec step definition format to the format required by Cucumber. Admittedly, my toy application is tiny in comparison to a typical production application, but I get the feeling that migrating a larger code base would not be too troublesome. The more adventurous may even wish to automate the migration process. More advice on migrating from RSpec scenarios can be found here

Steady Evolution

It is very encouraging to see the tooling around BDD evolve so that the task of mapping textual scenarios to code is now extremely simple. Certainly much easier than the previous generations of BDD frameworks. The Java community are well served by JBehave and the Ruby community now have Cucumber. Now that the technical challenges in mapping scenarios to code have largely been solved, teams can focus their efforts on collaborating with stakeholders and fellow team members to define the desired behaviour of the system being developed. After all, isn't that what BDD is all about?

Tuesday 21 October 2008

Exposed Scenario Implementation

In my previous post I refactored a noisy scenario method so that it communicated the required scenario steps more clearly. Although this was a huge improvement in terms of readability the SignInAcceptanceScenarios class still has a significant weakness; maintainability due to the exposure of a number of implementation details.

Here is the current state of the sign-in scenario:


public class SignInAcceptanceScenarios {

private WebDriver driver;

@Before
public void setup() {
driver = new HtmlUnitDriver();
}

@Test
public void shouldPresentKnownUserWithTheWelcomePage() {

Credentials credentials = new Credentials("ryangreenhall", "password");

givenAnExistingUserWith(credentials);
whenUserLogsInWith(credentials);
thenTheUserIsPresentedWithTheWelcomePage();
}

private void givenAnExistingUserWith(Credentials credentials) {
User user = new UserBuilder().
withCredentials(credentials).
build();

UserRespository respository = new UserRespository();
respository.create(user);
}

private void whenUserLogsInWith(Credentials credentials) {
browseToHomePage();
enterUsernameAndPassword(credentials);
clickSignInButton();
}

private WebDriver browseToHomePage() {
driver.get("http://www.example.com/sign-in");
return driver;
}

private void enterUsernameAndPassword(Credentials credentials) {
driver.findElement(By.id("username")).sendKeys(credentials.getUserName());
driver.findElement(By.id("password")).sendKeys(credentials.getPassword());
}

private void pressSignInButton() {
driver.findElement(By.id("login")).submit();
}

private void thenTheUserIsPresentedWithTheWelcomePage() {
Assert.assertEquals("Welcome", driver.getTitle());
}
}

Violating the Single Responsibility Principle

Following the Single Responsibility Principle we know that a class should have only one reason to change. The SignInAcceptanceScenario is responsible for ensuring that the identified sign-in scenarios execute correctly. Let's consider how many reasons it has to change:

  1. The sign in resource changes: e.g. /log-in;
  2. We want to replace Web Driver with another web testing framework;
  3. The parameter names for username and password change;
  4. The title of the welcome page changes;
  5. The behaviour of the application changes;

We have identified that our scenario class has five reasons to change! The only valid reason for this class to change is when the behaviour of the sign in process changes. For example, rather than presenting the user with the welcome page they are taken to their profile page, a common feature for most social networking sites these days.

Clearly with so many reasons to change, acceptance scenarios written in this style have the potential to require many changes throughout the lifetime of the application.

Abstraction and Encapsulation to the Rescue

Wouldn't it be great if we could encapsulate our scenarios from implementation details such as the location of the sign-in resource and the parameter names used to communicate the users credentials? This would allow the implementation of the application to change without modifying our scenarios.

Currently when implementing the sign in scenario we are thinking in terms of the abstractions provided by the Web, for example, browse to the home page and submit parameters to a sign-in resource. Wouldn't it be great if we could raise the level of abstraction and just sign in to the application using credentials, asking the resulting page if it is the welcome page?

Let's briefly consider one possible approach.

Fluent Navigation

Rather than exposing the implementation details of how we are interacting with application we need a suitable abstraction. One such abstraction involves representing each page in the application as a Page Object. The Page Object Model, introduced to me by my colleague Dan Bodart and also recommended by the WebDriver team, nicely encapsulates the internal representation of a page and provides methods for appropriate interactions. Another nice feature of the Page Object Model is that we can make use of a fluent interface to allow seamless navigation through any number of pages.

The goal here is to demonstrate the value of introducing a suitable abstraction for interacting with the application. I will therefore leave detailed descriptions of the implementation in the interest of brevity.

SignInPage

Given that the scenario in the example involves signing in to the application we will need a SignInPage that allows credentials to be entered and submitted.

For example:


import com.example.domain.Credentials;

public class SignInPage implements Page {

public SignInPage() {
}

public SignInPage with(Credentials credentials) {
// enter the username and password
return this;
}

public Page submit() {
// submit the username and password to the sign-in resource
// and return a Page representation

// of the response.
}

public String getTitle() {
...
}
}

Application Facade

Now that we have a SignInPage how can our SignInAcceptanceScenarios class get hold of one? The SignInPage will be dispensed by a class called MyApp, which acts a facade for the application providing methods to access various pages in the application. This approach nicely decouples the scenario from the URLs used to address pages in the application.

For example:


import com.example.web.pages.HomePage;
import com.example.web.pages.Page;
import com.example.web.pages.SignInPage;

public class MyApp {

public static SignInPage signIn() {
// GET the sign in page and return a sign in page object
}
}

Matching Pages

We now have the ability to navigate to the sign-in page, enter the users credentials and submit, receiving a resultant page. The only remaining functionality required by the sign-in scenario is to ensure that the page returned as a result of submitting user credentials is the welcome page. How can we encapsulate the sign-in scenario from knowing the internals of the welcome page? This sounds like a job for a Hamcrest matcher. We will create a WelcomePageMatcher that knows if a given page is the welcome page by inspecting the title of the page.

For example:


import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import com.example.web.pages.Page;

public class WelcomePageMatcher extends BaseMatcher {

public boolean matches(Object actualPage) {
return "Welcome".equals(((Page)actualPage).getTitle());
}

public void describeTo(Description description) {
}

public static WelcomePageMatcher isWelcomePage() {
return new WelcomePageMatcher();
}
}

Bringing Everything Together

The application facade, SignInPage and WelcomePageMatcher can be combined to provide a very concise specification of the behaviour required when users sign-in to the example application.


import com.example.domain.builders.UserBuilder;
import com.example.domain.Credentials;
import com.example.domain.User;
import com.example.persistence.UserRespository;
import static com.example.web.MyApp.signIn;
import com.example.web.pages.Page;
import static com.example.web.pages.matchers.WelcomePageMatcher.isWelcomePage;
import org.junit.Test;

public class SignInAcceptanceScenarios {

@Test
public void shouldPresentKnownUserWithTheWelcomePage() {
Page pageAfterLogIn = null;
Credentials credentials =
new Credentials("ryangreenhall", "password");

givenAnExistingUserWith(credentials);
whenUserLogsInWith(credentials, pageAfterLogIn);
thenUserIsPresentedWithTheWelcomePage(pageAfterLogIn);
}

// Alternatively we could have:
@Test
public void shouldPresentKnownUserWithTheWelcomePage() {
Credentials credentials =
new Credentials("ryangreenhall", "password");

// Given
givenAnExistingUserWith(credentials);

// When
Page pageAfterLogin = signIn().with(credentials).submit();

// Then
ensureThat(pageAfterLogin, isWelcomePage());
}

// Alternatively we can combine the when and then steps in a single line:
@Test
public void shouldPresentKnownUserWithTheWelcomePage() {
Credentials credentials =
new Credentials("ryangreenhall", "password");

givenAnExistingUserWith(credentials);

ensureThat(signIn().with(credentials).submit(),
respondsWithWelcomePage());
}


private void givenAnExistingUserWith(Credentials credentials) {
User user = new UserBuilder().
withCredentials(credentials).
build();

UserRespository respository = new UserRespository();
respository.create(user);
}

private void whenUserLogsInWith(Credentials credentials, Page pageAfterLogIn) {
pageAfterLogIn = signIn().with(credentials).submit();
}

private void thenUserIsPresentedWithTheWelcomePage(Page pageAfterLogin) {
ensureThat(page, isWelcomePage());
}
}

Summary

We have seen that the introduction of a simple internal DSL to interact with the application has greatly improved the readability of this scenario. Furthermore the SignInAcceptanceScenarios class is now completely decoupled from the implementation of the application making it less susceptible to change.

We can now change the following concerns without modifying the SignInAcceptanceScenario:

  1. Location of the sign in resource (encapsulated in the SignInPage class);
  2. Web testing framework (encapsulated in both the Application Facade and Page classes);
  3. The parameter names for username and password (encapsulated in the SignInPage);
  4. The title of the welcome page changes (encapsulated in the WelcomePageMatcher);

The SignInAcceptanceScenarios class now has only one responsibility; defining the behaviour of the application and thus should only require modification when the behaviour of the application changes.

Sunday 19 October 2008

Noisy Scenario Methods

This is the second entry in a series of posts that provide practical advice on how to avoid or refactor away from common functional testing smells.

Noisy scenario methods can generally be identified by the presence of long methods, which fail to highlight the important interactions with the application clearly. The code driving the application will typically be at a low level of abstraction adding to the noise. For web applications this will involve requesting resources, posting parameters and ensuring the expected response is returned. For example:


public class SignInAcceptanceScenarios {

@Test
public void shouldPresentKnownUserWithTheWelcomePage() {

User user = new UserBuilder().
withUsername("ryangreenhall").
withPassword("password").
build();

UserRespository respository = new UserRespository();
respository.create(user);

WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.example.com");

driver.findElement(By.id("username")).sendKeys("ryangreenhall");
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("login")).submit();

Assert.assertEquals("Welcome", driver.getTitle());
}
}

When reading scenarios I like to see clear descriptions of the steps that are taken when interacting with the application. The main problem with noisy scenario methods is that the reader has to filter through the noise to figure out the following: what is the starting state of the system? What interactions occur? An additional problem is that the reader is required to think at a low level of abstraction. Rather than thinking about signing in to the application we are forced to think in terms of posting parameters representing the username and password to a sign-in resource.

Discovering the Scenario Steps

Reading the example scenario we can see that ensuring a known user is presented with the welcome page requires the following steps:

  1. Create a user
  2. Navigate to the applications home page
  3. Fill in the sign in form with known credentials
  4. Submit the signin form
  5. Ensure that the user is taken to the welcome page

Some would argue that the example scenario could be improved with the introduction of comments prior to each step. However, I favour scenarios that are composed of small methods, whose names clearly describe: the starting state of the application, the interactions with the application and the expected outcomes. This allows the scenario to be expressed in terms of the domain without distracting the reader with the implementation details.

The Given-When-Then scenario format popularised by Behaviour Driven Development is a good starting point for structuring scenarios.

Making Your Code Read Like a Scenario

The following example shows how the original scenario has been improved using a series of Extract Method refactorings in order to communicate the important steps in the scenario, namely: create a new user, sign in with known credentials and ensure that the user is presented with the welcome page.


public class SignInAcceptanceScenarios {

private WebDriver driver;

@Before
public void setup() {
driver = new HtmlUnitDriver();
}

@Test
public void shouldPresentKnownUserWithTheWelcomePage() {

Credentials credentials = new Credentials("ryangreenhall", "password");

givenAnExistingUserWith(credentials);
whenUserLogsInWith(credentials);
thenTheUserIsPresentedWithTheWelcomePage();
}

private void givenAnExistingUserWith(Credentials credentials) {
User user = new UserBuilder().
withCredentials(credentials).
build();

UserRespository respository = new UserRespository();
respository.create(user);
}

private void whenUserLogsInWith(Credentials credentials) {
browseToHomePage();
enterUsernameAndPassword(credentials);
clickSignInButton();
}

private WebDriver browseToHomePage() {
driver.get("http://www.example.com/sign-in");
return driver;
}

private void enterUsernameAndPassword(Credentials credentials) {
driver.findElement(By.id("username")).sendKeys(credentials.getUserName());
driver.findElement(By.id("password")).sendKeys(credentials.getPassword());
}

private void pressSignInButton() {
driver.findElement(By.id("login")).submit();
}

private void thenTheUserIsPresentedWithTheWelcomePage() {
Assert.assertEquals("Welcome", driver.getTitle());
}
}

Structuring scenario methods in this style allows the reader to quickly understand the behaviour expected of the application in the context of a given scenario. Furthermore given that they read like written scenarios in terms of the problem domain they can be used to assist in conversations with QAs and Business Analysts, in addition to serving as useful documentation for future maintainers.

Thursday 16 October 2008

Mind Mapping Behaviour Driven Development

I recently presented an overview of Behaviour Driven Development at my current client. To help gather my thoughts I created the following mind map and have made it available here as others may find it useful.


mind-mapping-bdd

This mind map distills information from the following sources:

Tuesday 14 October 2008

Non Descriptive Scenario Method Name

This is the first entry in a series of posts that provide practical advice on how to avoid or refactor away from common functional testing smells.

Non descriptive scenario method names can easily be identified by the presence of extremely short method names that provide little or no insight into the scenario being executed. For example:


public class SignInAcceptanceScenarios {

@Test
public void signIn() {
...
}
}

So, what sign in scenario is being executed here? Known user? Unknown user? The only way to find out is to read what the method is doing. Variations on this theme include partial attempts to describe the scenario. For example:


public class SignInAcceptanceScenarios {

@Test
public void signInHappyScenario() {
...
}

@Test
public void signInSadScenario() {
...
}
}

Using story and scenario identifiers in scenario method names should also be avoided. Who would like to hazard a guess as to what behaviour the following scenarios describe?


public class SignInAcceptanceScenarios {

@Test
public void story145Scenario1() {
...
}

@Test
public void story145Scenario2() {
...
}

@Test
public void story345Scenario1() {
...
}
}

The use of scenario revealing method names in each of the examples would be far more helpful.

Scenario Revealing Method Names

I tend to prefer descriptive method names that describe the scenario being executed. A downside of this style is that it can lead to some very long method names. However, I would rather read a longer method name than a shorter one that has some important part of the scenario missing. Alternatively, if method names get ridiculously long then they can often be rephrased in a more concise manner. Personally I don't worry too much about long method names. When writing scenarios I aim for an accurate and clear description of the scenario being executed.

Non descriptive scenario methods can easily be renamed, once the scenario has been understood, so that the scenario is clearly described using a scenario revealing method name. For example:


public class SignInAcceptanceScenarios {

@Test
public void shouldPresentKnownUserWithTheWelcomePage() {
...
}

@Test
public void shouldDeclineUnknownUserAndAskThemToTryAgain() {
...
}

@Test
public void shouldLockAccountAfterThreeSubsequentFailedSignInAttempt() {
...
}
}

A subtle alternative to prefixing scenario method names with 'should' is to simply provide a description of the expected behaviour. I shall leave it as an exercise for readers to decide which style they prefer. My only advice, as with most things when developing software, is to be consistent. For example:


public class SignInAcceptanceScenarios {

@Test
public void knownUserIsPresentedWithTheWelcomePage() {
...
}

@Test
public void unknownUserIsDeclinedAndAskedToTryAgain() {
...
}

@Test
public void userAccountIsLockedAfterThreeSubsequentFailedSignInAttempts() {
...
}
}

Scenario revealing methods are a huge improvement over their less descriptive counterparts, allowing readers to quickly grasp the intended behaviour
of a given functional area. The improved SignInAcceptanceScenarios class really does serve as documentation describing the behaviour of the sign in functionality provided by the application.

Tuesday 30 September 2008

The Rise of Modern Legacy Code

Legacy code, as defined by Michael Feathers in Working Effectively with Legacy Code, is code that is without tests and difficult to change. I would like to suggest that there is a new breed of legacy code emerging with the increasing adoption of Test Driven Development and more recently Behaviour Driven Development; Modern legacy code.

These days, if you are lucky, you may encounter code bases with large suites of both unit and functional tests (perhaps I should say examples, specs or scenarios these days!). However, in some cases, although these tests serve as a reliable regression suite guarding against defects being introduced when adding new features, they may fail to clearly describe the desired behaviour of the system clearly.

In my opinion modern legacy code is code that has good functional and unit test coverage, but where the tests (especially functional) fail to clearly communicate the desired behaviour of the application increasing the cost of maintenance. This is a shame as with a little care and focus on readability it is possible to write functional tests that really do serve as documentation describing the behaviour of the application.

Should the concept of modern legacy be used as an excuse to not write functional tests? Absolutely not. Modern legacy should be a term that is used both to encourage teams to search for better ways to express their tests with the goal of improving readability and to seek out approaches that make functional tests easier to write. Modern legacy is a huge improvement over traditional legacy but there is still plenty of room for improvement in how we ensure that our applications are behaving themselves.

In a future post I plan to identify common functional test smells that I have encountered and to provide practical advice on how to spruce them up so that they describe the behaviour of the application more clearly.

In the meantime have a look at the functional tests in your application. Do they clearly describe the behaviour of your application? A good acid test is to ask a developer from another team if they can understand what your application is supposed to do by reading the functional tests for a given functional area. If you observe a puzzled stare followed by a series of WTFs then you may have some modern legacy code.

Sunday 28 September 2008

What is The Role of QA?

Zero Defects!

What would you think of a QA who told you that they had not found a single defect in the last month?

  • Lazy?
  • Unimaginative?
  • Been on holiday?
  • An accomplished QA?
The answer to this question depends solely on how one views the role of QA in the development process. Let's consider two hugely contrasting views of the role of QA in the context of two very different styles of development.

Team Foo

Team Foo work in a waterfall manner where each function of development: requirements, analysis, design, coding and QA are performed by different groups, in series. Communication among the different groups is achieved through documentation, with many members of the various teams having never met in person.

After a period of development, QA receive a "completed" system and have to answer the following question, often presented by management: Is the developed system fit for purpose, or in other words can we ship? This is a huge responsibility.

The sad reality for QAs working within this process is that they play no part in defect prevention to assist in ensuring the desired quality. They are only able to either detect the absence of quality through the identification of defects, or acknowledge that the system is of sufficient quality to be released. QAs therefore embark on a quest to find as many defects a possible. After all who wants to to be responsible for "signing off" a defect ridden product into production?

QAs adopt a destructive mindset and actively attempt to break the system using usage scenarios that may or may not be realistic; after all a shared understanding of the acceptance criteria for each feature has not been established. Bug reports are entered into the bug tracking system, assigned to development and the code and fix cycle begins. Bug fixes introduce new defects resulting in rising tensions and frustration between developers and QA and ultimately a late delivery.

Anyone has has worked in similar team setup will tell you that defects are common place. To make matters worse development and QA often engage in debates about whether raised bugs are in fact defects or a misinterpretation of the requirements.

Defects are expected in this environment and in some cases might be used as a measure of quality - "we have found and fixed 89 defects - we have a quality product now". Any claim of finding zero defects would almost certainly be frowned upon and may be used as a metric to suggest poor performance.

Team Bar

Team Bar form a cross functional team comprised of business people, business analysts, developers and QAs sitting on the same floor, within earshot of one another. The team work collaboratively toward a common goal set by the business who actively work with technical people to ensure that they understand the risks and opportunities provided by the project.

QA are heavily involved in the analysis of requirements and work closely with business analysts to define the acceptance criteria that features must fulfill to be deemed complete. Prior to starting work on a story, developers engage in a conversation with QAs to ensure that the acceptance criteria is understood. During this conversation it is not uncommon for developers to say something like: "We seemed to have missed the timeout scenario. What shall we do in this case?" The QA may reply "Oh yes, I didn't think of that, let's retry for a maximum of three times".

Upon completion of a feature, developers provide a demonstration to both QAs and business analysts to verify that their work fulfills the acceptance criteria defined for the feature. Any defects or missing features identified at this stage can be resolved efficiently by the original developer (or developers if pairing).

The goal for QA is to ensure that quality is built into the product from the beginning. The acceptance criteria used to judge the product's quality is clearly communicated to the whole team to ensure that the correct product is built. QA will still independently verify that the acceptance criteria for each story has been fulfilled.

A zero defect rate would be celebrated and considered to be a result of close collaboration between QAs, business analysts and developers both prior to and throughout development of features. QAs will have worked hard to identify realistic scenarios prior to features being developed and will have clearly communicated the acceptance criteria by which features will be deemed complete.

Changing Opinions on the focus of QA

It is very interesting to note that QA communities, predating the Agile and Lean movements, acknowledge that the focus of QA has changed considerably as the discipline has matured and developed over the past fifty years.

In the paper, The Growth of Software Testing (1988) , the shifting focus of QA is categorized as follows:


























PeriodFocus
1956
Debugging - Programs are written and then tested by the programmer until they are satisfied that any bugs have been removed.
1957 - 1978
Demonstration - Testing demonstrates that the system does what it is supposed to do.
1979 - 1982
Destruction - The focus of testing changes from proving the system does what is supposed to do, to the identification of defects.
1983 - 1987
Evaluation - Testing becomes an activity throughout the development life cycle.
1988
Prevention - The focus is on defect prevention. Tests were written to demonstrate that software satisfies its specification, to detect faults and to prevent faults.

Perhaps Test Driven Development is not so extreme after all?

Zero Defects - Really?

I have known of several projects that fit the profile of the Bar team. Did they achieve zero defects? The honest answer is no. They did, however, reduce defects to a manageable level. Unpredictable, demoralising cycles of code and fix have been long forgotten on these teams. Where a defect is found it is followed up with a root cause analysis to determine how the defect was introduced so that it can be avoided in the future.

Note that while QAs in the Bar team place heavy emphasis on defect prevention they still ensure that the behaviour required of the system is present and correct according to the specified acceptance criteria.

Summary

In both teams the goal of QA is to ensure that the system is fit for purpose and provides the features agreed with the customer. We have seen two contrasting styles of development and the different roles that QA plays in each. Team Foo focus on the identification of defects and bug reporting whereas Team Bar focus on preventing defects.

The Poppendieck's have it right when they describe a process that regularly results in defects being found as a broken process. Defects should be a rarity rather than the norm. If identification of defects is commonplace in your organisation then you have a problem.

Software development has suffered for too long as a result of poor collaboration between QA and development. What can you do to encourage collaboration between these two groups? You could try starting with the following statement: As a company we value defect prevention over defect identification.

Saturday 6 September 2008

Behaviour Driven Development: by Example

To coincide with the release of the wonderful JBehave 2, I have made available an introductory BDD article, Behaviour Driven Development: By Example, using JBehave 2 as the example BDD framework.

The goal of the article is to introduce newcomers to BDD using a worked example, documenting a BDD style development process starting with a story scenario through to working code.

Comments and suggestions for improvements are most welcome.

If you are working in a Java development team who are envious of RSpec's Story Runner, and JRuby is a little too radical for your environment, then JBehave 2 is just what you have been waiting for.

Congratulations to the JBehave 2 team!