B
Behaviour
ehaviour D
Driven
riven D
Development
evelopment
Slide 6
Slide 6 text
Problem
Problem
Slide 7
Slide 7 text
Kako je klijent opisao proizvod.
Kako je klijent opisao proizvod.
Slide 8
Slide 8 text
Kako je vođa projekta razumeo.
Kako je vođa projekta razumeo.
Slide 9
Slide 9 text
Kako ga je programer implementirao.
Kako ga je programer implementirao.
Slide 10
Slide 10 text
Šta su beta testeri dobili.
Šta su beta testeri dobili.
Slide 11
Slide 11 text
Šta je klijentu zaista bilo potrebno.
Šta je klijentu zaista bilo potrebno.
Slide 12
Slide 12 text
Rešenje
Rešenje
Slide 13
Slide 13 text
Hajde da svi koristimo istu
Hajde da svi koristimo istu
terminologiju
terminologiju
Menadžeri
Programeri
Biznis analitičari
Vlasnici projekta
Testeri
...
Slide 14
Slide 14 text
...za planiranje,
...za planiranje,
implementaciju i testiranje
implementaciju i testiranje
funkcionalnosti
funkcionalnosti
Menadžeri
Programeri
Biznis analitičari
Vlasnici projekta
Testeri
...
Slide 15
Slide 15 text
...sa fokusom na ponašanje
...sa fokusom na ponašanje
Menadžeri
Programeri
Biznis analitičari
Vlasnici projekta
Testeri
...
Slide 16
Slide 16 text
StoryBDD nam pomaže da razvojni tim
StoryBDD nam pomaže da razvojni tim
razume biznis logiku na istom nivou kao
razume biznis logiku na istom nivou kao
klijent.
klijent.
I čak podiže nivo znanja klijenta o
I čak podiže nivo znanja klijenta o
sopstvenom biznisu
sopstvenom biznisu.
.
Slide 17
Slide 17 text
Ali kako?
Ali kako?
Slide 18
Slide 18 text
Primoravajući vas da
Primoravajući vas da
odgovorite na tri
odgovorite na tri
jednostavna pitanja.
jednostavna pitanja.
Slide 19
Slide 19 text
Ko?
Ko?
Šta?
Šta?
Kako?
Kako?
Slide 20
Slide 20 text
Ko ima koristi?
Ko ima koristi?
Upotrebna vrednost.
Upotrebna vrednost.
Opis funkcionalnosti.
Opis funkcionalnosti.
Slide 21
Slide 21 text
Gherkin
Gherkin
Slide 22
Slide 22 text
Gherkin
Gherkin
Struktuirani jezik kojim se
Struktuirani jezik kojim se
opisuje funkcionalnost.
opisuje funkcionalnost.
Slide 23
Slide 23 text
Feature: News admin panel
In order to maintain a list of news
As a site administrator
I need to be able to edit news
Slide 24
Slide 24 text
Feature: News admin panel
In order to maintain a list of news
As a site administrator
I need to be able to edit news
Slide 25
Slide 25 text
Feature: (naziv funkcionalnosti)
In order to (upotrebna vrednost)
As a (osoba koja koristi)
I need (opis funkcionalnosti)
Slide 26
Slide 26 text
Feature: News admin panel
In order to maintain a list of news
As a site administrator
I need to be able to edit news
Scenario: Add new article
Given I am on the "/admin/news" page
When I click "New Article"
And I fill in "Title" with "Learn BDD"
And I press "Save"
Then I should see "A new article was added"
Slide 27
Slide 27 text
Feature: News admin panel
In order to maintain a list of news
As a site administrator
I need to be able to edit news
Scenario: Add new article
Given I am on the "/admin/news" page
When I click "New Article"
And I fill in "Title" with "Learn BDD"
And I press "Save"
Then I should see "A new article was added"
Slide 28
Slide 28 text
Feature: News admin panel
In order to maintain a list of news
As a site administrator
I need to be able to edit news
Scenario: (naziv scenarija)
Given (podesi stanje sistema)
When (akcija osobe/uloge)
And (se može dodati za više akcija...)
And (...Given/When/Then linije)
Then (proveri stanje sistema)
Slide 29
Slide 29 text
Gherkin
Gherkin
Konzinstentan način da se
Konzinstentan način da se
opišu funkcionalnosti i
opišu funkcionalnosti i
scenariji korišćenja istih.
scenariji korišćenja istih.
Slide 30
Slide 30 text
I to je nešto.
I to je nešto.
Slide 31
Slide 31 text
Behat
Behat
Slide 32
Slide 32 text
Zamislite da možemo da
Zamislite da možemo da
izvršavamo Gherkin rečenice
izvršavamo Gherkin rečenice
kao funkcionalne testove.
kao funkcionalne testove.
Slide 33
Slide 33 text
Behat
Behat
Mapira svaki korak
Mapira svaki korak
(Gherkin rečenicu) u PHP
(Gherkin rečenicu) u PHP
poziv.
poziv.
Konzolna aplikacija
Konzolna aplikacija
$ ./bin/behat --help
Usage:
behat [-s|--suite="..."] [-f|--format="..."] [-o|--out="..."] [--format-settings="..."] [--init] [
Arguments:
paths Optional path(s) to execute. Could be:
- a Symfony2 bundle path (@BundleName/)
- a dir (features/)
- a feature (*.feature)
- a scenario at specific line (*.feature:10).
- all scenarios at or after a specific line (*.feature:10-*).
- all scenarios at a line within a specific range (*.feature:10-20).
- a scenarios list file (*.scenarios).
Options:
--suite (-s) Only execute a specific suite.
--format (-f) How to format tests output. pretty is default.
Available formats are:
- progress: Prints one character per step.
- pretty: Prints the feature as is.
You can use multiple formats at the same time. (multiple values allowed)
--out (-o) Write format output to a file/directory instead of
STDOUT (output_path). You can also provide different
Slide 36
Slide 36 text
Inicijalizacija
Inicijalizacija
$ php bin/behat --init
+d features - place your *.feature files here
+d features/bootstrap - place your context classes here
+f features/bootstrap/FeatureContext.php - place your definitions, transformations and hook
Slide 37
Slide 37 text
Behatu je potrebno:
Behatu je potrebno:
*.feature fajlovi za izvšenje.
FeatureContext.php koji sadrži metode za izvršenje.
Opcioni behat.yml konfiguracioni fajl.
Slide 38
Slide 38 text
Linus Torvalds nije
Linus Torvalds nije
razvijao Linux
razvijao Linux
koristeći BDD
koristeći BDD
Slide 39
Slide 39 text
Ali mi možemo!
Ali mi možemo!
Slide 40
Slide 40 text
Feature: ls
In order to see the directory structure
As a UNIX user
I need to be able to list directory's contents
features/ls.feature
Slide 41
Slide 41 text
Scenario
Scenario
Ako imamo dva fajla u
Ako imamo dva fajla u
direktorijumu, i pokrenemo
direktorijumu, i pokrenemo
ls komandu - trebalo bi da
ls komandu - trebalo bi da
ih vidimo u listi.
ih vidimo u listi.
Slide 42
Slide 42 text
Scenario: List 2 files in a directory
Given I have a file named "foo"
And I have a file named "bar"
When I run "ls"
Then I should see "foo" in the output
And I should see "bar" in the output
features/ls.feature
Slide 43
Slide 43 text
No content
Slide 44
Slide 44 text
$ php bin/behat
$ php bin/behat
$ php bin/behat
Feature: ls
In order to see the directory structure
As a UNIX user
I need to be able to list directory's contents
Scenario: List 2 files in a directory # features/ls.feature:6
Given I have a file named "foo"
And I have a file named "bar"
When I run "ls"
Then I should see "foo" in the output
And I should see "bar" in the output
1 scenario (1 undefined)
5 steps (5 undefined)
0m0.01s (10.10Mb)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Given I have a file named :arg1
*/
Slide 45
Slide 45 text
Implementiraj generisane
Implementiraj generisane
metode
metode
/**
* @Given I have a file named :file
*/
public function iHaveAFileNamed($file)
{
touch($file);
}
/**
* @When I run :command
*/
public function iRun($command)
{
$this->output = shell_exec($command);
}
Slide 46
Slide 46 text
$ php bin/behat
$ php bin/behat
$ php bin/behat
Feature: ls
In order to see the directory structure
As a UNIX user
I need to be able to list directory's contents
Scenario: List 2 files in a directory # features/ls.feature:6
Given I have a file named "foo" # FeatureContext::iHaveAFileNamed()
And I have a file named "bar" # FeatureContext::iHaveAFileNamed()
When I run "ls" # FeatureContext::iRun()
Then I should see "foo" in the output # FeatureContext::iShouldSeeInTheOutput()
And I should see "bar" in the output # FeatureContext::iShouldSeeInTheOutput()
1 scenario (1 passed)
5 steps (5 passed)
0m0.02s (10.22Mb)
Slide 47
Slide 47 text
Možemo da
Možemo da
mapiramo svaki
mapiramo svaki
korak u PHP poziv
korak u PHP poziv
sa Behatom.
sa Behatom.
Slide 48
Slide 48 text
Nije loše
Nije loše
Slide 49
Slide 49 text
Mink
Mink
Slide 50
Slide 50 text
Mink
Mink
Mink je
Mink je open sors
open sors pregledač
pregledač
kontroler/emulator za
kontroler/emulator za web
web
aplikacije.
aplikacije.
Slide 51
Slide 51 text
Zajednički API
Zajednički API
Goutte
Selenium
Zombie.js
...
Slide 52
Slide 52 text
Korišćenje Mink-a
Korišćenje Mink-a
use Behat\Mink\Session;
use Behat\Mink\Driver\GoutteDriver;
$session = new Session(new GoutteDriver());
$session->visit($startUrl);
$session->getPage()->findLink('Downloads')->click();
echo 'Status: '.$session->getPage()->getStatusCode();
echo 'Content: '.$session->getPage()->getContent();
Slide 53
Slide 53 text
Mink unutar FeatureContext
Mink unutar FeatureContext
Slide 54
Slide 54 text
Mink Extension
Mink Extension
Jednostavno korišćenje
Jednostavno korišćenje
Mink-a unutar
Mink-a unutar
FeatureContext klase.
FeatureContext klase.
Mink unutar FeatureContext
Mink unutar FeatureContext
klase
klase
namespace Hypebeast\Bundle\WebBundle\Behat;
use Behat\MinkExtension\Context\RawMinkContext;
class FeatureContext extends RawMinkContext
{
public function doSomething()
{
$this->getSession()->visit('https://github.com/');
}
}
Slide 57
Slide 57 text
No content
Slide 58
Slide 58 text
FeatureContext extends MinkContext
FeatureContext extends MinkContext
namespace Hypebeast\Bundle\WebBundle\Behat;
use Behat\MinkExtension\Context\RawMinkContext;
class FeatureContext extends MinkContext
{
public function doSomething()
{
$this->visit('/foo');
$this->selectOption('Country', 'Poland');
$this->pressButton('Save');
$this->assertPageContainsText('Country changed.');
}
}
Slide 59
Slide 59 text
Nakon
Nakon
dodavanja MinkContext
dodavanja MinkContext
$ php bin/behat -dl
default | Given /^(?:|I )am on (?:|the )homepage$/
default | When /^(?:|I )go to (?:|the )homepage$/
default | Given /^(?:|I )am on "(?P[^"]+)"$/
default | When /^(?:|I )go to "(?P[^"]+)"$/
default | When /^(?:|I )reload the page$/
default | When /^(?:|I )move backward one page$/
default | When /^(?:|I )move forward one page$/
default | When /^(?:|I )press "(?P(?:[^"]|\\")*)"$/
default | When /^(?:|I )follow "(?P(?:[^"]|\\")*)"$/
default | When /^(?:|I )fill in "(?P(?:[^"]|\\")*)" with "(?P(?:[^"]|\\")*)"
default | When /^(?:|I )fill in "(?P(?:[^"]|\\")*)" with:$/
default | When /^(?:|I )fill in "(?P(?:[^"]|\\")*)" for "(?P(?:[^"]|\\")*)"$
default | When /^(?:|I )fill in the following:$/
default | When /^(?:|I )select "(?P(?:[^"]|\\")*)" from "(?P(?:[^"]|\\")*)
default | When /^(?:|I )additionally select "(?P(?:[^"]|\\")*)" from "(?P(
default | When /^(?:|I )check "(?P(?:[^"]|\\")*)"$/
default | When /^(?:|I )uncheck "(?P(?:[^"]|\\")*)"$/
default | When /^(?:|I )attach the file "(?P[^"]*)" to "(?P(?:[^"]|\\")*)"$/
default | Then /^(?:|I )should be on "(?P[^"]+)"$/
default | Then /^(?:|I )should be on (?:|the )homepage$/
default | Then /^the (?i)url(?-i) should match (?P"(?:[^"]|\\")*")$/
Slide 60
Slide 60 text
Što znači
Što znači
Možemo pisati funkcionalne
Možemo pisati funkcionalne
testove bez potrebe za
testove bez potrebe za
pisanjem i jedne linije PHP
pisanjem i jedne linije PHP
koda!
koda!
Slide 61
Slide 61 text
No content
Slide 62
Slide 62 text
Feature: Search
In order to find articles
As a website visitor
I need to be able to search for articles
Scenario: Searching for an article that exists
Given I am on the homepage
When I fill in "search" with "BDD"
And I press "go"
And I follow "Behavior-driven development"
Then I should see "History"
And I should see "Principles of BDD"
And I should see "Story versus specification"