AT10 Concurrent Session 11/8/2012 3:45 PM

"Specification-by-Example: A Cucumber Implementation"

Presented by:

Mary Thorn Deutsche Bank

Brought to you by:

340 Corporate Way, Suite 300, Orange Park, FL 32073 888‐268‐8770 ∙ 904‐278‐0524 ∙ [email protected] ∙ www.sqe.com

Mary Thorn Deutsche Bank

VP of QA at Deutsche Bank Global Technologies in North Carolina, Mary Thorn has a broad testing background that spans automation, data warehouses, and web-based systems in a wide variety of technologies and testing techniques. During her more than fifteen years of experience in healthcare, HR, and SaaS-based products, Mary has held manager and contributor level positions in organizations. She has a strong interest in methodologies and direct experience leading agile teams through Scrum adoption and beyond. Mary is a Certified ScrumMaster and an active participant in Triangle Institute of Software Quality Assurance.

.

Mary Thorn

z QA Manager at Deutsche Bank. z Over 15 years of QA experience working in the following areas: Healthcare, HR, Agriculture, Financial and SaaS- based products. z Have a broad testing background that spans automation, data warehouses to web-based systems in a wide variety of technologies and testing techniques. z Heavy interest in Agile Testing Methodologies and direct experience leading Agile teams in the SCRUM Software Development Lifecycle (SDLC).

1 • Introduction

• The Communication Problem

• What are Acceptance Tests?

• Simple Example

with Cucumber

• Feature Files

• Wrap up

Goal: Presenter would like to have a successful presentation

Acceptance Criteria: 1. Verify the attendees stay awake 2. Verify the attendees are happy with the presentation

2 The Challenge: z Today, the most difficult problem in software development is knowing what to build, not how to build it. z Knowing what to build, requires knowing why it is being built. In other words, understanding the goal.

The Problem: z Stories typically concentrate on the what and the how, not the why. Goals and examples are usually missing. z Stories are usually a list of imperative (acceptance criteria). z Imperative requirements are usually interpreted in subtly different ways by each person. If goals and examples are absent, misinterpretation is much more likely.

3 Example: z : Draw a star with 10 points.

OR

Solution: Specification by Example z People understand requirements best using concrete examples. z Examples clear up ambiguity and misunderstandings. z Examples expose missing requirements. z Examples force everyone to think harder about a problem.

4 Specification by Example z This is the basis of acceptance testing and Behavior Driven Design (BDD). z It is critical that everyone participates in creating the examples so that the understanding is shared. z Ultimately, acceptance testing is less about the example itself and more about the conversation required to create the example.

What does this have to do with automated testing?

5 In a nutshell, automated accepttttance tests are executable examples that define the system's specifications.

Acceptance Tests are z Formal examples that define requirements. z Executable. z Self-explanatory and readable by all team members. z Tests of business rules. z A living specification of system behavior.

6 Acceptance Tests do NOT z Test pieces of code in isolation. They are not a substitute for unit and integration tests. z Verify the entire system. z Verify all permutations of a piece of functionality. z Use mock objects except to remove a dependency on an external 3rd party.

Benefits:

z Higher quality b/c everyone shares the same understanding of the requirements and builds it right the first time.

z Tests become the system's regression suite.

z Create an objective verification of “done-ness” for a story. A story is done when all tests pass.

z Create transppypgarency into progress on a stor y.

z Manual testers are part of the automation process.

z Allows for more exploratory testing b/c happy path is automated

7 Acceptance Criteria: Transactions are rounded to the nearest cent.

Original Value Rounded Value $0.021 $0.02 $0. 025 $0.02 $0.029 $0.02

Why was there confusion?

The goal was missing... Goal: Create a currency conversion system.

The Concrete Example clarified what was meant by the acceptance criteria . Refined Acceptance Criteria: Transactions are always rounded down to the nearest cent.

8 z This simple example is a REAL EXAMPLE in a system that was well-tested and approved b y all parties. z Attacker was able to steal > $15,000 starting with a single cent using this process... z $0.01 → 0.0051 € rounded to 0.01 € z 0.01 € → $0.0196 rounded to $0.02 z A seemingly minor ambiguity in the requirements was very expensive.

z Concrete examples drive understanding and consensus. z To create good representative examples, everyone must understand the goal of the story. z For technical people to properly understand the goal, they must understand the business domain.

9 What does Cucumber have to do with this?

• Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation of requirements, automated regression tests and development-aid - all rolled into one format. • Cucumber works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 40 spoken languages.

10 Components:

• Cucumber (Framework) • HTMLUnit (Browser Emulator) • Selinium/Watir (Browser Emulator API) • Features (Tests written in sentence format) • Step Definitions (Backend code to support Features)

Command line – Cucumber Feature File - Step Definition File – Rake TAGS - Framework - Tags Sentence Matching Sentence @abc

Terminal Browser Emulator Selinium/Watir – Result Output- Execute Command

11 Process: • Product Owner writes acceptance tests in feature file scenarios format in the story. Worst case, they at least start the : • During grooming the team discusses the scenarios and asks questions. Team can add/remove scenarios during grooming or team updates feature file after . • Once Sprint has started QA and Dev work on getting the feature file 90% complete before the developer starts coding.

Process: • The developers code the scenarios in the feature file in a TDD manner. • QA expands the scenarios in the feature files after development if there are new findings. • When testing is complete PO acceptance is done by running the acceptance tests.

12 Two Components: • The Feature files which contain the test Scenarios. • The Step Definition files which contain the Ruby “glue” code that connects the tests to the application.

Feature File Overview: z Written in plain text z Define the test suite and contain the actual tests which are called Scenarios z Written collaboratively by everyone on the team (PO, QA, and Dev) z QA can run these manually.

13 Feature: z Suite is defined by keyword “Feature:” followed by a description. This states the goal for the Feature File. When the Feature File is complete, a tag is included at this level so that all of the test Scenarios contained within the file can be run from a single command. Feature: This tests the currency conversion system

Background: z “Background:” is run before each test so that you don’t have to repeat steps. Equal to a setup step. Background: Given I login with the test account And I navigate to the Transaction Screen Then I should see the Transaction logo

14 Scenario: z Individual tests are defined by “Scenario:” followed by a unique name. Scenarios are concrete examples of how we want the software to behave. The first line states the goal of the given Scenario, while every line thereafter lists the steppps needed to complete the test.

z Scenario: Verify Transactions are rounded to the nearest cent.

Scenario Outline: z “Scenario Outline:” is used for data driven tests.

Scenario Outline: Verify Transactions are rounded to the nearest cent.

Given I am on the order screen When I make a of values Then the are rounded

Examples: |transacti on| val ues| |.021|.02| |.025|.02| |.029|.02|

15 Keywords: • Tests have reserved words that begin each line: Given, When, Then, And, But. • Use Given to state a precondition • Use When & And when taking an action • Use Then when asserting a validation

Scenario Outline: Verify Transactions are rounded to the nearest cent. Given I am on the order screen When I make a transaction of 9.025 And save the transaction Then the value should equal 9.02

Tags: • Tags a powerful tool to organize tests and scenarios. A Scenario or feature can have as many tags as you like. Just separate them with spaces. • A note to the wise: Keep it simple. @tag @smoke_test @component

16 @Cucumberpresentation Feature: User would like to have a successful presentation Tests the following acceptance criteria: 1. Verify the attendees are awake 2. Verify the attendees are happy with the presentation

@Attendeeawake Scenario: Verify the attendees are awake

Given that I am an attendee When I have drunk caffeine Then I will be able to listen to the presenter

@Attendeeishappy SiVifAttdhScenario: Verify Attendees are happy

Given I am the presenter When I talk slow And my content is interesting Then the attendees will be happy

z Cucumber is a functional tool for lean and agile teams. z It supports behavior-driven development, specification by examppgple and agile acceptance testin g. z You can use it to automate functional validation in a form that is easily readable and understandable to business users, developers and testers. z It helps teams create executable specifications, that are a goal for development, acceptance criteria and functional regression checks for future changes. z Allows teams to create living documentation, a single authoritative source of information on system functionality that is always up-to-date. z Allows manual testers to be involved in automation, as well as, frees them up from testing the “happy path” to be able to real exploratory testing.

17 QUESTIONS?

18