Professional Documents
Culture Documents
ADIS2020 Tema9 PDF
ADIS2020 Tema9 PDF
и дизајн на
информациски системи
Тема 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
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
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 _______
• 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
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
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 add(presenter)
@perks.push Perk.new(@host, presenter, 1, "beer")
end
end
class Perk
attr_reader :buyer, :receiver, :quantity, :item
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