Speed����������� ������������������ up����������� ������������������ web����������� ������������������ application����������� ������������������ development����������� ������������������ using����������� ������������������ Behaviour����������� ������������������ Driven����������� ������������������ Development9th����������� ������������������ European����������� ������������������ TYPO3����������� ������������������ Conference,����������� ������������������ ����������� ������������������ October����������� ������������������ 30th����������� ������������������ 2013
Martin����������� ������������������ Helmich,����������� ������������������ Mittwald����������� ������������������ CM����������� ������������������ [email protected]
Photo: „Rawhead“, CC BY-NC-SAhttp://www.flickr.com/photos/rawhead/3780249375/
YOUR����������� ������������������ SPEAKER
Martin����������� ������������������ HelmichSoftware����������� ������������������ Architect����������� ������������������ at����������� ������������������ Mittwald
TYPO3����������� ������������������ addicted����������� ������������������ since����������� ������������������ 2004Caffeine����������� ������������������ addicted����������� ������������������ since����������� ������������������ 2007
Show����������� ������������������ of����������� ������������������ hands:
Who����������� ������������������ has����������� ������������������ (not)����������� ������������������ heard����������� ������������������ of����������� ������������������ BDD?
Thesupermat,����������� ������������������ CC����������� ������������������ BY-SAhttp://commons.wikimedia.org/wiki/File:F%C3%AAte_de_l%27Humanit%C3%A9_2012_-_009.jpg
Franck����������� ������������������ Nieto,����������� ������������������ CC����������� ������������������ NC-BY-SAhttp://www.flickr.com/photos/francki/9686485433/
A����������� ������������������ (really����������� ������������������ short)����������� ������������������ introduction����������� ������������������ to
Scrum
Requirements����������� ������������������ are����������� ������������������ phrased����������� ������������������ as
User����������� ������������������ stories
As a <role>,I want <something>so that <benefit>
„Cohn,����������� ������������������ Mike:����������� ������������������ User����������� ������������������ Stories����������� ������������������ Applied����������� ������������������ -����������� ������������������ For����������� ������������������ Agile����������� ������������������ Software����������� ������������������ DevelopmentAddison-Wesley,����������� ������������������ 2004
Requirements����������� ������������������ are����������� ������������������ phrased����������� ������������������ as
User����������� ������������������ stories
As an anonymous user,I want to register on the siteso that I can use the site's
personalized services.
„
Each����������� ������������������ user����������� ������������������ story����������� ������������������ has
Acceptance����������� ������������������ criteria
In the menu, there is a „register“ item.On the register page the user can enter the following information:
user namereal nameemail address
After registration, the user should receive a confirmation email.
„
Product����������� ������������������ Backlog
Sprint����������� ������������������ Backlog
Sprint(1~4����������� ������������������ weeks)
Daily
ProductOwner
DevelopmentTeamProduct
Backlog
writesstories
SprintBacklog
Selectedby����������� ������������������ team
Productincrement
createdby����������� ������������������ team
Verifies����������� ������������������ thatacceptance����������� ������������������ criteria����������� ������������������ are����������� ������������������ met
Another(also����������� ������������������ really����������� ������������������ short)introduction����������� ������������������ to
TDD
„MacroShoots“,����������� ������������������ CC����������� ������������������ NC-BY-SAhttp://www.flickr.com/photos/41398593@N05/4365961229/
Failingtest
PassingtestRefactor
Test-Driven����������� ������������������ Development
Unit����������� ������������������ tests����������� ������������������ are
great!
Unit����������� ������������������ tests����������� ������������������ are
great!
But
not����������� ������������������ sufficient.
Acceptance����������� ������������������ Test����������� ������������������ using
PHPUnit����������� ������������������ &����������� ������������������ Selenium
<?phpclass MyTest extends PHPUnit_Extensions_Selenium2TestCase{ protected function setUp() { $this->setBrowser('*firefox'); $this->setBrowserUrl('http://login.mittwald.de/'); } public function testLoginWithCorrectCredentialsWorksCorrectly() { $this->url('login.html'); $this->byXPath('//input[@id="login_username"]')->value('123456'); $this->byXPath('//input[@id="login_password"]')->value('supersecret'); $this->byXPath('//input[@type="submit" and @name="login_password"]')->clickAndWait();
$this->frame(0); $this->assertContains( 'Welcome to the customer center', $this->byXPath('//body')->text() ); }}?>
Acceptance����������� ������������������ Test����������� ������������������ using
PHPUnit����������� ������������������ &����������� ������������������ Selenium
<?phpclass MyTest extends PHPUnit_Extensions_Selenium2TestCase{ protected function setUp() { $this->setBrowser('*firefox'); $this->setBrowserUrl('http://login.mittwald.de/'); } public function testLoginWithCorrectCredentialsWorksCorrectly() { $this->url('login.html'); $this->byXPath('//input[@id="login_username"]')->value('123456'); $this->byXPath('//input[@id="login_password"]')->value('supersecret'); $this->byXPath('//input[@type="submit" and @name="login_password"]')->clickAndWait();
$this->frame(0); $this->assertContains( 'Welcome to the customer center', $this->byXPath('//body')->text() ); }}?>
Hey,����������� ������������������ XPath����������� ������������������ expressions����������� ������������������ arereally����������� ������������������ cool! DEV
Acceptance����������� ������������������ Test����������� ������������������ using
PHPUnit����������� ������������������ &����������� ������������������ Selenium
<?phpclass MyTest extends PHPUnit_Extensions_Selenium2TestCase{ protected function setUp() { $this->setBrowser('*firefox'); $this->setBrowserUrl('http://login.mittwald.de/'); } public function testLoginWithCorrectCredentialsWorksCorrectly() { $this->url('login.html'); $this->byXPath('//input[@id="login_username"]')->value('123456'); $this->byXPath('//input[@id="login_password"]')->value('supersecret'); $this->byXPath('//input[@type="submit" and @name="login_password"]')->clickAndWait();
$this->frame(0); $this->assertContains( 'Welcome to the customer center', $this->byXPath('//body')->text() ); }}?>
SRSLY?����������� ������������������ WTF?
PO
Introducing
Gherkin
CC����������� ������������������ BY-SA����������� ������������������ http://commons.wikimedia.org/wiki/File:Spreewaldgurke2.jpg
Gherkin����������� ������������������ is����������� ������������������ a����������� ������������������ business-readable����������� ������������������ (business-writable?)����������� ������������������ domain-specific����������� ������������������ language����������� ������������������ for����������� ������������������ writing����������� ������������������ behaviour����������� ������������������ specifications.
CC����������� ������������������ BY-SA����������� ������������������ http://commons.wikimedia.org/wiki/File:Spreewaldgurke2.jpg
Introducing
Gherkin
Acceptance����������� ������������������ Test����������� ������������������ using
Gherkin����������� ������������������ and����������� ������������������ Behat&Mink
Scenario: User login Given I am on "login.mittwald.de" When I fill in "123456" for "username" And fill in "supersecret" for "password" And press "log in" Then I should see "Welcome to the customer center"
Acceptance����������� ������������������ Test����������� ������������������ using
Gherkin����������� ������������������ and����������� ������������������ Behat&Mink
Scenario: User login Given I am on "login.mittwald.de" When I fill in "123456" for "username" And fill in "supersecret" for "password" And press "log in" Then I should see "Welcome to the customer center"
I����������� ������������������ wrote����������� ������������������ this����������� ������������������ all����������� ������������������ by����������� ������������������ myself!
PO
<?phpclass MyTest extends PHPUnit_Extensions_Selenium2TestCase{ protected function setUp() { $this->setBrowser('*firefox'); $this->setBrowserUrl('http://login.mittwald.de/'); } public function testLoginWithCorrectCredentialsWorksCorrectly() { $this->url('login.html'); $this->byXPath('//input[@id="login_username"]')->value('123456'); $this->byXPath('//input[@id="login_password"]')->value('supersecret'); $this ->byXPath('//input[@type="submit" and @name="login_password"]') ->clickAndWait();
$this->frame(0); $this->assertContains( 'Welcome to the customer center', $this->byXPath('//body')->text() ); }}?>
Scenario: User login Given I am on "login.mittwald.de" When I fill in "123456" for "username" And fill in "supersecret" for "password" And press "log in" Then I should see "Welcome to the customer center"
24 6Lines����������� ������������������ of����������� ������������������ code
Toolsthat����������� ������������������ caninterpretGherkin
Florian����������� ������������������ Richter,����������� ������������������ CC����������� ������������������ BYhttp://www.flickr.com/photos/florianric/7263382550/
Cucumber Behat
Decym92,����������� ������������������ Public����������� ������������������ Domain,����������� ������������������ http://commons.wikimedia.org/wiki/File:Rubin013.JPGDrew����������� ������������������ McLellan,����������� ������������������ CC����������� ������������������ BY-NC,����������� ������������������ http://www.flickr.com/photos/drewm/3191872515/
Behat Mink
GoutteDriver
SeleniumDriver
WebDriver
SahiDriver
ZombieDriver
Selenium
Sahi
Zombie
Install����������� ������������������ using����������� ������������������ Composer
{ "require": { "behat/behat": "*", "behat/mink": "*", "behat/mink-extension": "*",
"behat/mink-goutte-driver": "*", "behat/mink-selenium-driver": "*", "behat/mink-selenium2-driver": "*", "behat/mink-sahi-driver": "*", "behat/mink-zombie-driver": "*" }}
You����������� ������������������ can����������� ������������������ use����������� ������������������ Behat����������� ������������������ for����������� ������������������ simple
UI����������� ������������������ tests.
Or����������� ������������������ use����������� ������������������ Behat����������� ������������������ for����������� ������������������ actual
Acceptance����������� ������������������ Tests.
Scenario: Registration form Given I am on "index.php?id=512" When I follow "register now!" And I fill in "user_name" with "Max Mustermann" And I fill in "user_email" with "[email protected]" And I attach the file "/Users/mmustermann/max.jpeg" to "user_image" And I press "submit registration" Then I should be on "index.php?id=514" And the response should contain "Thank you ..." And the mailbox "m15273" should contain an email with subject "Your registration"
Scenario: Registration form Given I am on "index.php?id=512" When I follow "register now!" And I fill in "user_name" with "Max Mustermann" And I fill in "user_email" with "[email protected]" And I attach the file "/Users/mmustermann/max.jpeg" to "user_image" And I press "submit registration" Then I should be on "index.php?id=514" And the response should contain "Thank you ..." And the mailbox "m15273" should contain an email with subject "Your registration"
This����������� ������������������ is����������� ������������������ NOT����������� ������������������ anacceptance����������� ������������������ test!
Better!
Feature: Online registration In order to use the site's personalized features As an anonymous user I want to register to the page.
Scenario: Registration is confirmed Given I am on the registration page And I fill in the following: | Full name | Max Mustermann | | Email address | [email protected] | And I upload an image of myself And submit the registration Then I should see a confirmation message And I should receive a confirmation email
Feature: Online registration In order to use the site's personalized features As an anonymous user I want to register to the page.
Scenario: Registration is confirmed Given I am on the registration page And I fill in the following: | Full name | Max Mustermann | | Email address | [email protected] | And I upload an image of myself And submit the registration Then I should see a confirmation message And I should receive a confirmation email
Who����������� ������������������ writes����������� ������������������ thestep����������� ������������������ definitions?
Then /^(?:I| ) should receive a confirmation e?mail$/ do # Connect to mailbox and see if mail is actually there. # Throw exception otherwise.end
class FeatureContext extends Context{ /** * @Then /^(?:|I )should receive a confirmation e?mail$/ */ public function assertRegistrationMailWasReceived() { // Connect to mailbox and see if mail is actually there. // Throw exception otherwise. }}
ProductOwner
Stories����������� ������������������ andacceptance����������� ������������������ tests
DevelopmentTeam
writes
iteratively����������� ������������������ refineimplement����������� ������������������ step����������� ������������������ definitionsuse����������� ������������������ as����������� ������������������ completion����������� ������������������ measure
Integrate����������� ������������������ acceptance����������� ������������������ tests����������� ������������������ into����������� ������������������ your����������� ������������������ continuous����������� ������������������ integration����������� ������������������ process!
(Try����������� ������������������ to����������� ������������������ run����������� ������������������ as����������� ������������������ many����������� ������������������ as����������� ������������������ possible����������� ������������������ on����������� ������������������ each����������� ������������������ build)
Possible����������� ������������������ CI����������� ������������������ build����������� ������������������ pipelinesInitial����������� ������������������ situation:����������� ������������������ No����������� ������������������ acceptance����������� ������������������ tests
Main
Deploy����������� ������������������ to����������� ������������������ Production
Run����������� ������������������ unit����������� ������������������ testsPerform����������� ������������������ CGL����������� ������������������ checksCompile����������� ������������������ stuff
Deploy����������� ������������������ to����������� ������������������ production����������� ������������������ system(e.g.����������� ������������������ using����������� ������������������ Surf,����������� ������������������ Capistrano,����������� ������������������ DPKG/Aptitude)
Easy,����������� ������������������ isn't����������� ������������������ it?
Possible����������� ������������������ CI����������� ������������������ build����������� ������������������ pipelinesVariant����������� ������������������ #1:����������� ������������������ Slow����������� ������������������ but����������� ������������������ safe
Main
Deploy����������� ������������������ to����������� ������������������ Staging
Run����������� ������������������ all����������� ������������������ AT's
Run����������� ������������������ unit����������� ������������������ testsPerform����������� ������������������ CGL����������� ������������������ checksCompile����������� ������������������ stuff
Deploy����������� ������������������ to����������� ������������������ staging����������� ������������������ system����������� ������������������ (e.g.����������� ������������������ using����������� ������������������ Surf,����������� ������������������ Capistrano,����������� ������������������ DPKG/Aptitude)Reset����������� ������������������ staging����������� ������������������ database����������� ������������������ to����������� ������������������ predefined����������� ������������������ state
Run����������� ������������������ all����������� ������������������ acceptance����������� ������������������ tests����������� ������������������ in����������� ������������������ staging����������� ������������������ system
Deploy����������� ������������������ to����������� ������������������ production����������� ������������������ systemDeploy����������� ������������������ to����������� ������������������ Production
Possible����������� ������������������ CI����������� ������������������ build����������� ������������������ pipelinesVariant����������� ������������������ #2:����������� ������������������ Fast����������� ������������������ but����������� ������������������ unsafe
Main
Deploy����������� ������������������ to����������� ������������������ Staging
Run����������� ������������������ all����������� ������������������ AT's
Deploy����������� ������������������ to����������� ������������������ staging����������� ������������������ systemReset����������� ������������������ staging����������� ������������������ database����������� ������������������ to����������� ������������������ predefined����������� ������������������ state
Run����������� ������������������ all����������� ������������������ acceptance����������� ������������������ tests����������� ������������������ in����������� ������������������ staging����������� ������������������ system.
Roll����������� ������������������ back����������� ������������������ production����������� ������������������ system����������� ������������������ if����������� ������������������ errors����������� ������������������ occur.
Deploy����������� ������������������ to����������� ������������������ Production
Rollback����������� ������������������ Production
Possible����������� ������������������ CI����������� ������������������ build����������� ������������������ pipelinesVariant����������� ������������������ #3:����������� ������������������ Somewhere����������� ������������������ in����������� ������������������ between
Main
Deploy����������� ������������������ to����������� ������������������ Staging
Run����������� ������������������ critical����������� ������������������ AT's
Run����������� ������������������ only����������� ������������������ critical����������� ������������������ acceptance����������� ������������������ tests����������� ������������������ in����������� ������������������ staging����������� ������������������ system
Run����������� ������������������ all����������� ������������������ AT's
Rollback����������� ������������������ Production
Run����������� ������������������ remaining����������� ������������������ acceptance����������� ������������������ tests����������� ������������������ in����������� ������������������ staging����������� ������������������ system
Rollback����������� ������������������ production����������� ������������������ system����������� ������������������ if����������� ������������������ errors����������� ������������������ occured
Deploy����������� ������������������ to����������� ������������������ Production
How����������� ������������������ to
sellBDD
or„I‘m����������� ������������������ already����������� ������������������ paying����������� ������������������ you����������� ������������������ for����������� ������������������ unit����������� ������������������ tests,����������� ������������������ why����������� ������������������ the����������� ������������������ ****����������� ������������������ should����������� ������������������ I����������� ������������������ now����������� ������������������ pay����������� ������������������ for����������� ������������������ accepance����������� ������������������ tests,����������� ������������������ too!?“
Dirk����������� ������������������ Houbrechts,����������� ������������������ CC����������� ������������������ BY-NChttp://www.flickr.com/photos/houbi/9583306027/
BDD����������� ������������������ allows����������� ������������������ to...
reduce����������� ������������������ the����������� ������������������ amount����������� ������������������ of����������� ������������������ time����������� ������������������ spent����������� ������������������ on����������� ������������������ software����������� ������������������ testing.
Nick����������� ������������������ Olejniczak,����������� ������������������ CC����������� ������������������ BY-NChttp://www.flickr.com/photos/nicholasjon/4498088305/
BDD����������� ������������������ allows����������� ������������������ to...
measure����������� ������������������ progress����������� ������������������ easily����������� ������������������ and����������� ������������������ objectively
Sven����������� ������������������ Van����������� ������������������ Echelpoel,����������� ������������������ CC����������� ������������������ BY-NC-SAhttp://www.flickr.com/photos/s7nn3/5468396537/
Bogdan����������� ������������������ Sudito,����������� ������������������ CC����������� ������������������ BYhttp://www.flickr.com/photos/bogdansuditu/2377844553/
BDD����������� ������������������ allows...
the����������� ������������������ customer����������� ������������������ to����������� ������������������ phrase����������� ������������������ more����������� ������������������ precise����������� ������������������ specifications.
the����������� ������������������ developer����������� ������������������ to����������� ������������������ implement����������� ������������������ specifications����������� ������������������ more����������� ������������������ precisely.
BDD����������� ������������������ allows����������� ������������������ to...
create����������� ������������������ software����������� ������������������ that����������� ������������������ works(and����������� ������������������ keeps����������� ������������������ working)
Arthur����������� ������������������ John����������� ������������������ Picton,����������� ������������������ CC����������� ������������������ BYhttp://www.flickr.com/photos/arthurjohnpicton/5364226117/
Duncan����������� ������������������ Hull,����������� ������������������ CC����������� ������������������ BYhttp://www.flickr.com/photos/dullhunk/202872717/
References
Gärtner,����������� ������������������ Markus:����������� ������������������ ATDD����������� ������������������ in����������� ������������������ der����������� ������������������ Praxis,����������� ������������������ dpunkt.Verlag����������� ������������������ 2013Linz,����������� ������������������ Tilo:����������� ������������������ Testen����������� ������������������ in����������� ������������������ Scrum-Projekten,����������� ������������������ dpunkt.Verlag����������� ������������������ 2013
North,����������� ������������������ Dan:����������� ������������������ Introducing����������� ������������������ BDD,����������� ������������������ http://dannorth.net/introducing-bdd/,����������� ������������������ 2006
Cohn,����������� ������������������ Mike:����������� ������������������ User����������� ������������������ Stories����������� ������������������ Applied,����������� ������������������ Addison-Wesley����������� ������������������ 2004
Literature