"Specification-by-Example: A Cucumber Implementation" - - PDF document

specification by example
SMART_READER_LITE
LIVE PREVIEW

"Specification-by-Example: A Cucumber Implementation" - - PDF document

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


slide-1
SLIDE 1

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 ∙ sqeinfo@sqe.com ∙ www.sqe.com

slide-2
SLIDE 2

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 software development organizations. She has a strong interest in agile testing 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. .

slide-3
SLIDE 3

1

Mary Thorn

QA Manager at Deutsche Bank. Over 15 years of QA experience working in the following

areas: Healthcare HR Agriculture Financial and SaaS areas: Healthcare, HR, Agriculture, Financial and SaaS- based products.

Have a broad testing background that spans

automation, data warehouses to web-based systems in a wide variety of technologies and testing techniques.

Heavy interest in Agile Testing Methodologies and direct Heavy interest in Agile Testing Methodologies and direct

experience leading Agile teams in the SCRUM Software Development Lifecycle (SDLC).

slide-4
SLIDE 4

2

  • Introduction
  • The Communication Problem
  • What are Acceptance Tests?
  • Simple Example
  • Acceptance Testing with Cucumber
  • Feature Files

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

slide-5
SLIDE 5

3

The Challenge:

Today, the most difficult problem in software

development is knowing what to build, not how to build it.

Knowing what to build, requires knowing why it

is being built. In other words, understanding the goal. The Problem:

Stories typically concentrate on the what and

the how, not the why. Goals and examples are usually missing.

Stories are usually a list of imperative

requirements (acceptance criteria).

Imperative requirements are usually interpreted Imperative requirements are usually interpreted

in subtly different ways by each person. If goals and examples are absent, misinterpretation is much more likely.

slide-6
SLIDE 6

4

Example:

Requirement: Draw a star with 10 points.

OR Solution: Specification by Example People understand requirements best using

People understand requirements best using

concrete examples.

Examples clear up ambiguity and

misunderstandings.

Examples expose missing requirements. Examples force everyone to think harder about

a problem.

slide-7
SLIDE 7

5

Specification by Example This is the basis of acceptance testing and

This is the basis of acceptance testing and

Behavior Driven Design (BDD).

It is critical that everyone participates in creating

the examples so that the understanding is shared.

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?

slide-8
SLIDE 8

6

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

Acceptance Tests are Formal examples that define requirements

Formal examples that define requirements. Executable. Self-explanatory and readable by all team

members.

Tests of business rules Tests of business rules. A living specification of system behavior.

slide-9
SLIDE 9

7

Acceptance Tests do NOT Test pieces of code in isolation They are not a

Test pieces of code in isolation. They are not a

substitute for unit and integration tests.

Verify the entire system. Verify all permutations of a piece of functionality. Use mock objects except to remove a Use mock objects except to remove a

dependency on an external 3rd party. Benefits:

Higher quality b/c everyone shares the same

understanding of the requirements and builds it right the first time.

Tests become the system's regression suite. Create an objective verification of “done-ness” for a

  • story. A story is done when all tests pass.

Create transparency into progress on a story.

p y p g y

Manual testers are part of the automation process. Allows for more exploratory testing b/c happy path is

automated

slide-10
SLIDE 10

8

Acceptance Criteria: Transactions are rounded to the nearest cent. Original Value Rounded Value $0.021 $0 025 $0.02 $ $0.025 $0.029 $0.02 $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 by the acceptance criteria. Refined Acceptance Criteria: Transactions are always rounded down to the nearest cent.

slide-11
SLIDE 11

9

This simple example is a REAL EXAMPLE in a

system that was well-tested and approved by all y pp y parties.

Attacker was able to steal > $15,000 starting

with a single cent using this process...

$0.01 → 0.0051 € rounded to 0.01 € 0.01 € → $0.0196 rounded to $0.02 A seemingly minor ambiguity in the

requirements was very expensive.

Concrete examples drive understanding and

consensus.

To create good representative examples,

everyone must understand the goal of the story.

For technical people to properly understand the

goal, they must understand the business domain domain.

slide-12
SLIDE 12

10

What does at 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

y, , ,

  • r web applications written in any language. It

has been translated to over 40 spoken languages.

slide-13
SLIDE 13

11

Components:

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

Features) Features)

Command line – Rake TAGS - @abc Cucumber Framework - Tags Feature File - Sentence Step Definition File – Matching Sentence Terminal Browser Emulator Selinium/Watir – Terminal Result Output- Browser Emulator Selinium/Watir Execute Command

slide-14
SLIDE 14

12

Process:

  • Product Owner writes acceptance tests in

p feature file scenarios format in the story. Worst case, they at least start the Scenario:

  • During grooming the team discusses the

scenarios and asks questions. Team can add/remove scenarios during grooming or team updates feature file after 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

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.

slide-15
SLIDE 15

13

Two Components:

  • The Feature files which contain the test
  • 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: Written in plain text

Written in plain text Define the test suite and contain the actual tests

which are called Scenarios

Written collaboratively by everyone on the team

(PO, QA, and Dev)

QA can run these manually.

slide-16
SLIDE 16

14

Feature: Suite is defined by keyword “Feature:” followed

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. g Feature: This tests the currency conversion system Background: “Background:” is run before each test so that

  • 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 And I navigate to the Transaction Screen Then I should see the Transaction logo

slide-17
SLIDE 17

15

Scenario: Individual tests are defined by “Scenario:”

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 steps needed to complete the test. p p

Scenario: Verify Transactions are rounded

to the nearest cent. Scenario Outline:

“Scenario Outline:” is used for data driven tests

  • 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 <transaction> of values Then the <values> are rounded Examples: |t ti | l | |transaction|values| |.021|.02| |.025|.02| |.029|.02|

slide-18
SLIDE 18

16

Keywords:

  • Tests have reserved words that begin each line:

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
  • 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

slide-19
SLIDE 19

17

@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

  • 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 S i V if Att d h Scenario: Verify Attendees are happy Given I am the presenter When I talk slow And my content is interesting Then the attendees will be happy

  • Cucumber is a functional test automation tool for lean and

agile teams.

  • It supports behavior-driven development, specification by

example and agile acceptance testing. p g p g

  • You can use it to automate functional validation in a form that

is easily readable and understandable to business users, developers and testers.

  • It helps teams create executable specifications, that are a

goal for development, acceptance criteria and functional regression checks for future changes.

  • Allows teams to create living documentation, a single
  • Allows teams to create living documentation, a single

authoritative source of information on system functionality that is always up-to-date.

  • 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.

slide-20
SLIDE 20

18

QUESTIONS?