BDD • BDD ~= TDD + DDD • Specification as Ubiquitous Language • Colloboration between developers and non-techies • “outside-in” methodology driven by business value 12年11月3⽇日星期六
Writing tests is Hard • Where to start • What to test and what not to test • How much to test in one go • What to call their tests • How to understand why a test fails 12年11月3⽇日星期六
In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Feature: List directory contents 12年11月3⽇日星期六
Scenario: List 2 files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ 12年11月3⽇日星期六
Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ 12年11月3⽇日星期六
Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ Context 12年11月3⽇日星期六
Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ Context 12年11月3⽇日星期六
Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ Context Event(s) 12年11月3⽇日星期六
When (Event) When I am on "/some/page" When I fill "username" with "everzet" When I fill "password" with "123456" When I press "login" When I call "ls -la" 12年11月3⽇日星期六
Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ Context Event(s) 12年11月3⽇日星期六
Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ Context Event(s) Outcome(s) 12年11月3⽇日星期六
Feature: ls In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ 12年11月3⽇日星期六
Feature: ls In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ 12年11月3⽇日星期六
https://github.com/cucumber/gherkin/blob/master/lib/gherkin/i18n.json # language: en Scenario: Regular numbers Given I have entered 3 into the calculator And I have entered 2 into the calculator When I press divide Then the result should be 1.5 on the screen # language: de Szenario: Normale Zahlen Gegeben sei ich habe 3 in den Taschenrechner eingegeben Und ich habe 2 in den Taschenrechner eingegeben Wenn ich divide drücke Dann sollte das Ergebniss auf dem Bildschirm 1.5 sein # language: zh-TW 場景: 將兩個數相除 假設我已經在計算機上輸⼊入 3 ⽽而且我已經在計算機上輸⼊入 2 當我按下 divide 那麼螢幕上應該顯⽰示 1.5 # language: ja シナリオ: ふつうの数値 前提 3 を⼊入⼒力 かつ 2 を⼊入⼒力 もし divide を押した ならば 1.5 を表⽰示 12年11月3⽇日星期六
“Overall I’ve been really impressed with Behat. I would never have imagined that Behat and Mink were going to even compare to Cucumber and Capybara, but it does!!” Brett, Lead Web Developer at BBC 12年11月3⽇日星期六
ls.feature 1 Feature: ls 2 In order to see the directory structure 3 As a UNIX user 4 I need to be able to list the current directory's contents 5 6 Scenario: List 2 files in a directory 7 Given I am in a directory "test" 8 And I have a file named "foo" 9 And I have a file named "bar" 10 When I run "ls" 11 Then I should get: 12 """ 13 bar 14 foo 15 """ 12年11月3⽇日星期六
Feature: ls In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory # features/ls.feature:6 Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ 1 scenario (1 undefined) 5 steps (5 undefined) 0m0.019s 12年11月3⽇日星期六
You can implement step definitions for undefined steps with these snippets: /** * @Given /^I am in a directory "([^"]*)"$/ */ public function iAmInADirectory($arg1) { throw new PendingException(); } /** * @Then /^I should get:$/ */ public function iShouldGet(PyStringNode $string) { throw new PendingException(); } 12年11月3⽇日星期六
Feature: ls In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory # features/ls.feature:6 Given I am in a directory "test" # FeatureContext::iAmInADirectory() TODO: write pending definition And 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 get: # FeatureContext::iShouldGet() """ bar foo """ 1 scenario (1 pending) 5 steps (4 skipped, 1 pending) 0m0.018s 12年11月3⽇日星期六
$ behat Feature: ls In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ 1 scenario (1 passed) 5 steps (5 passed) 0m0.03s 12年11月3⽇日星期六
Tags @billing Feature: Verify billing @important Scenario: Missing product description @bicker @annoy Scenario: Several products Only execute the features or scenarios with tags matching tag filter expression 12年11月3⽇日星期六
Placeholder Scenario Outline: controlling order Given there are cucumbers When I eat cucumbers Then I should have cucumbers Examples: | start | eat | left | | 12 | 5 | 7 | | 5 | 3 | 2 | 12年11月3⽇日星期六