10. BDD (Behaviour Driven Development)
• Not test, specify!
• It should ...
• Expressive
• Test as Documentation
11. RSpec example
describe Bowling do
describe '#score' do
context 'all gutter game' do
before do
@bowling = Bowling.new
20.times { @bowling.hit(0) }
end
it 'should equal 0' do
@bowling.score.should eq(0)
end
end
end
end
12. RSpec example
describe Bowling do
describe '#score' do
context 'all gutter game' do
before do
@bowling = Bowling.new
20.times { @bowling.hit(0) }
end
it 'should equal 0' do
@bowling.score.should eq(0)
end
end
end
end Not Test, Specify
13. RSpec example
describe Bowling do
describe '#score' do
context 'all gutter game' do
before do
@bowling = Bowling.new
20.times { @bowling.hit(0) }
end
it 'should equal 0' do
@bowling.score.should eq(0)
end
end
end
end It should ...
14. RSpec example
describe Bowling do
describe '#score' do
context 'all gutter game' do
before do
@bowling = Bowling.new
20.times { @bowling.hit(0) }
end
it 'should equal 0' do
@bowling.score.should eq(0)
end
end
end
end Expressive
15. RSpec example
describe Bowling do
describe '#score' do
Test a
context 'all gutter game' do
s
before do
Docum
@bowling = Bowling.new
20.times { @bowling.hit(0) }
entati
end
o n
it 'should equal 0' do
@bowling.score.should eq(0)
end
end
end
end
18. PHPUnit example
class BowlingTest extends PHPUnit_Framwork_TestCase
{
private $_bowling;
public function setUp()
{
$this->_bowling = new Bowling;
}
public function testScore0ForAllGutterGame()
{
for ($i = 0; $i <= 20; $i++) {
$this->_bowling->hit(0);
}
$this->assertEquals(0, $this->_bowling->score);
}
}
19. PHPSpec example
class DescribeBowling extends PHPSpecContext
{
private $_bowling;
public function before()
{
$this->_bowling = $this->spec(new Bowling);
}
public function itShouldScore0ForAllGutterGame()
{
for ($i=1; $i<=20; $i++) {
$this->_bowling->hit(0);
}
$this->_bowling->score->should->equal(0);
}
}
20. PHPSpec example
class DescribeBowling extends PHPSpecContext
{
private $_bowling;
public function before()
{
$this->_bowling = $this->spec(new Bowling);
}
public function itShouldScore0ForAllGutterGame()
{
for ($i=1; $i<=20; $i++) {
$this->_bowling->hit(0);
}
$this->_bowling->score->should->equal(0);
}
}
Not Test, Specify
21. PHPSpec example
class DescribeBowling extends PHPSpecContext
{
private $_bowling;
public function before()
{
$this->_bowling = $this->spec(new Bowling);
}
public function itShouldScore0ForAllGutterGame()
{
for ($i=1; $i<=20; $i++) {
$this->_bowling->hit(0);
}
$this->_bowling->score->should->equal(0);
}
}
It should ...
22. PHPSpec example
class DescribeBowling extends PHPSpecContext
{
private $_bowling;
public function before()
{
$this->_bowling = $this->spec(new Bowling);
}
public function itShouldScore0ForAllGutterGame()
{
for ($i=1; $i<=20; $i++) {
$this->_bowling->hit(0);
}
$this->_bowling->score->should->equal(0);
}
}
Expressive
23. PHPSpec example
class DescribeBowling extends PHPSpecContext
{
Test a
private $_bowling;
Docum s
public function before()
{
$this->_bowling = $this->spec(new Bowling);
entati
}
public function itShouldScore0ForAllGutterGame()
o n
{
for ($i=1; $i<=20; $i++) {
$this->_bowling->hit(0);
}
$this->_bowling->score->should->equal(0);
}
}