Cairo Noleto

Suporte para Behaviour Driven Development (BDD) e Histórias (Stories) no PHPUnit 3.3

| Comments

Agora o PHPUnit tem suporte para Behaviour Driven Development (BDD) e criação de histórias (Stories). Além de Test-Driven Development (TDD) agora BDD no PHPUnit.

Nesse artigo do Sebastian Bergmann, ele demonstra como utilizar BDD no PHPUnit descrevendo uma partida de boliche. O que eu achei legal foi o formato de saída:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
sb@vmware ~ % phpunit --story BowlingGameSpec
PHPUnit @package_version@ by Sebastian Bergmann.
BowlingGameSpec
 - Score for gutter game should be 0 [successful]
   Given New game
    Then Score should be 0
 - Score for all ones is 20 [successful]
   Given New game
    When Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
     and Player rolls 1
    Then Score should be 20
 - Score for one spare is 16 [successful]
   Given New game
    When Player rolls 5
     and Player rolls 5
     and Player rolls 3
    Then Score should be 16
 - Score for one strike is 24 [successful]
   Given New game
    When Player rolls 10
     and Player rolls 3
     and Player rolls 4
    Then Score should be 24
 - Score for perfect game is 300 [successful]
   Given New game
    When Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
     and Player rolls 10
    Then Score should be 300
Scenarios: 5, Failed: 0, Skipped: 0, Incomplete: 0.

Comments