You are on page 1of 36

Анализа

и дизајн на
информациски системи

Тема 9
Спецификација по пример
Благодарност за
Declan Whelan
Shawn Wallace
Waterfall

Source: http://www.cs.umd.edu/class/spring2003/cmsc838p/Process/waterfall.pdf
Agile Specification
Типичен пристап

Build

Specification Test
Deploy
Tests Cases

И тогаш ќе се појави
Последици
Behavior Driven Design
• Перспектива на корисник
• Се тестира однесувањето на системот
• Executable requirements
• Има директна повратна врска
• Рачно враќање и поправање е прескапо
Acceptance Tests vs. Unit Tests

• Unit Test потврдува дека кодот е добар (INSIDE


OUT)
• Acceptance Test потврдува дека модулот е
добар (OUTSIDE IN)

8
Acceptance Tests vs. Unit Tests

9
http://www.deltamatrix.com/2012-04-17-04-37-50/horizontal-and-vertical-user-stories-slicing-the-cake
http://www.deltamatrix.com/2012-04-17-04-37-50/horizontal-and-vertical-user-stories-slicing-the-cake
Build it Right
Business Failure Business Success

Specification By
Example

Build the Right Thing

Useless Crap Maintenance Nightmare


Specification By Example
Gojko Adzic, 2011 page 4
What are Specifications
By Example?
• Thin slices of system behaviour
• that deliver business value
• described as concrete examples
• that are potentially automatable
• without translation
• to create executable specifications
• captured in live documentation.
Source: https://docs.google.com/drawings/d/1cbfKq-KazcbMVCnRfih6zMSDBdtf90KviV7l2oxGyWM/edit
Specification By Example
Business Goal
Derive the scope
Scope
Specify collaboratively
Key Examples
Refine the specification
Specification With Examples
Automate literally
Executable Specification
Validate frequently
Living Documentation
Derive the Scope: User Stories

As a _______
I want to _______
So that _______

As a student
I want to purchase used books online
So that I can save money
Колаборациски работилници

• Три члена:
– програмер
– тестер
– аналитичар
Пример Спецификација

Given _______
When _______
Then _______

Given “War and Peace” is available as a used book for $2.99


When Susan selects book“War and Peace”
Then “Buy used for $2.99” is displayed
Refining the Specification
“Specifications with examples are acceptance tests”
Gojko Adzic

• Be precise and make sure spec is testable


• Avoid “scripts” and “flows”
• Focus on business functionality not design
• Avoid UI details
• Avoid covering every possible combination
Automating Examples

• Start small
• Select important examples for automation
• Plan up-front to automate
• Be prepared to go slower at the start
• Treat automation code as a first class citizen
• Avoid record and playback
• Avoid using pre-populated data
Validate Frequently
• Start with a Continuous Integration system
• Set up a Continuous Deployment system
• Specify and test business logic separately
from end-to-end flows
• Organize tests along functional lines
• Run all test nightly
• Consider an iteration “test pack”
Living Documentation
• Keep specifications short
• Evolve a specification language and leverage
in with “common fixtures”
• Make documentation accessible - consider
a wiki
• Organize the documentation
• Put specifications under version control
• Describes how software should behave in plain text
• Gherkin
– Usable in many different human languages
– Features can be written and understood by both non/technical project
members
• Not a replacement for unit testing; it’s not a low level
testing/spec framework
• Easy to execute in Continuous Integration environment (except
MS TFS)
Technology Stack
• Cucumber - Domain Specification
• Ruby, JRuby or .NET - map cukes to application
• UI testing framework - Watir, Watin, Selenium,
Capybara (headless), anything that supports
WebDriver
• Open source
• STRONG community support

23
Features
• Who’s using the system?
• What are they doing?
• Why do they care?

• As a <role>
• I want <feature>
• So that <business value>
Who’s Using the System

What are they doing?

Why do they care?

Features
Scenarios
• Features are defined by one or more scenarios
• Sequence of steps thru the feature that exercises on
path
• Use BDD style – given-when-then

• Scenario: <description>
• <step 1>
• …
• <step 2>
Scenarios
• Given
–Sets up preconditions, or context, for the scenario
• When
–The action, or behavior, that we’re focused on
• Then
–Checks post-conditions
–Verifies that the right thing happened in the When
stage
• And
• Given - Sets up preconditions, or context, for the scenario
• When - The action, or behavior, that we’re focused on
• Then - Checks post-conditions and verifies that the right thing
happened in the When stage

Scenarios
Cucumber Organization

Step
Features
Definitions

Call
System
Under Test
Feature File
Feature: Turn cucumber into beer
As a cucumber presenter
I want beer after my presentation
So I can enjoy the rest of day

Scenario: Vlado buys Marija beer


Given Vlado hosts ADIS
When Marija demos Cucumber
Then Vlado should buy Marija 1 beer
Step Definitions
Given /^(.+) hosts/ do |host|
@event = Event.new(host)
end

When /^(.+) demos/ do |presenter|


@event.add(presenter)
end

Then /^(.+) should buy (.+) (\d+) (.*)$/ do |buyer, drinker, qty, item|
perk = @event.perks[0];
perk.buyer.should == buyer; perk.receiver.should == drinker
perk.quantity.should == quantity.to_i; perk.item.should == item
end
System Under Test
class Event
attr_reader :perks

def initialize(host) @host = host; @perks = [] end

def add(presenter)
@perks.push Perk.new(@host, presenter, 1, "beer")
end
end

class Perk
attr_reader :buyer, :receiver, :quantity, :item

def initialize(buyer, receiver, quantity, item)


@buyer = buyer; @receiver = receiver
@quantity = quantity; @item = item
end
end
Execution
Scenario: Vlado buys Marija beer
Given Vlado hosts ADIS
When Marija demos Cucumber
Then Vlado should buy Marija 1 beer
Given /^(.+) hosts/ do |host| When /^(.+) demos/ do |presenter|
@event = Event.new(host) “Vlado”
@event.add(presenter)
End end

Then /^(.+) should buy (.+) (\d+) (.*)$/ do |buyer, drinker, qty, item|
perk = @event.perks[0];
perk.buyer.should == buyer; perk.receiver.should == drinker
perk.quantity.should == quantity.to_i; perk.item.should == item
end
Execution
Scenario: Vlado buys Marija beer
Given Vlado hosts ADIS
When Marija demos Cucumber
Then Vlado should buy Marija 1 beer
Given /^(.+) hosts/ do |host| When /^(.+) demos/ do |presenter|
@event = Event.new(host) @event.add(presenter)
End end

“Marija”
Then /^(.+) should buy (.+) (\d+) (.*)$/ do |buyer, drinker, qty, item|
perk = @event.perks[0];
perk.buyer.should == buyer; perk.receiver.should == drinker
perk.quantity.should == quantity.to_i; perk.item.should == item
end
Execution
Scenario: Vlado buys Marija beer
Given Vlado hosts ADIS
When Marija demos Cucumber
Then Vlado should buy Marija 1 beer
Given /^(.+) hosts/ do |host| When /^(.+) demos/ do |presenter|
@event = Event.new(host) @event.add(presenter)
End end

Then /^(.+) should buy (.+) (\d+) (.*)$/ do |buyer, drinker, qty, item|
perk = @event.perks[0];
perk.buyer.should == buyer; perk.receiver.should == drinker
perk.quantity.should == quantity.to_i; perk.item.should == item
end
Reading
Specification By Example
Gojko Adzic

You might also like