BDD is an extension of the good-known and widely used TDD methodology. It improves TDD's efficiency and fixes its most common problems by allowing developers to focus on the essence of programming. It also allows to improve the communication between software engineers and business professionals, making the whole development process easier and more effective.
Precise and Complete Requirements? An Elusive Goal
Why you should be doing BDD
1. 1
WHY YOU SHOULD BE
DOING BDD
MATEUSZ ZALEWSKI
@mpzalewski
https://github.com/Zales0123
2. BDD is a process designed to aid the management and the delivery of software
development projects by improving communication between engineers and
business professionals.
BEHAVIOR DRIVEN
DEVELOPMENT
2
http://inviqa.com/insights/bdd-guide
15. We are going to
increase sale by
selling more
products
GOAL
We are planning to
achieve a 10% increase
in sale in our web store
in 4 months
15
16. EXAMPLES
Given "PHP T-Shirt" is priced at €100.00
And the store has "VAT" tax rate of 23%
When I add product "PHP T-Shirt" to the cart
Then my cart taxes should be €23.00
16
20. 20
✦ it adds two numbers
✦ it multiplies two numbers
✦ it subtracts two numbers
✦ it divides two numbers
✦ it not allows to divide by 0
WHAT DOES
CALCULATOR DO?
21. 21
HOW HARD CAN IT BE?
class CalculatorSpec extends ObjectBehavior
{
function it_adds_two_numbers()
{
$this->add(4, 5)->shouldReturn(9);
}
function it_multiplies_two_numbers()
{
$this->multiply(3, 8)->shouldReturn(24);
}
function it_does_not_allow_to_divide_by_0()
{
$this
->shouldThrow(‘InvalidArgumentException’)
->during(‘divide’, [10, 0])
;
}
}
22. 22
class ValidationMessageProviderSpec extends ObjectBehavior
{
function it_provides_happy_message_if_validation_passed(
Validator $validator,
ValidatedObject $object
) {
$validator->validate($object)->willReturn(true);
$this->provide($object)->shouldReturn(‘Great! Everything is fine!’);
}
}
HAVING FUN WITH MOCKS
23. THINK IN CODE
CODE IS GOOD
23
http://phpsrbija.rs/tday2014/img/portfolio/phpspec.png
24. STORY
24
It is an ancient need to be told stories. But the
story needs a great storyteller.
~ Alan Rickman
26. FEATURE
26
In order to pay less while buying goods
As a Customer
I want to receive discount for my purchase
Receiving percentage discount promotion on order
27. SCENARIO
27
Given "PHP T-Shirt" is priced at €100.00
And the store has "VAT" tax rate of 23%
When I add product "PHP T-Shirt" to the cart
Then my cart taxes should be €23.00