Click here to load reader
Upload
giulio-de-donato
View
3.724
Download
3
Embed Size (px)
DESCRIPTION
BDD is not only for rubists :)
Citation preview
@liuggio
IT’S ALL ABOUT BEHAVIOUR-ALSO IN PHP-
PUG-ROMA 26-02-2013
WHY WE DO TESTS?
> refactor
> automation
> verification
> ??
WHO LOVES TDD?
"Test-Driven Development is a developer practice that involves writing tests before writing the code being tested."
<<TDD is a design tool
used to deliver high-quality code >>
REFACTOR IS TIME CONSUMING
RED GREEN REFACTOR
TDD: THE INFINTE CYCLE
"Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication"
TECHNOLOGIC
TDD: THE INFINTE CYCLE
If you have a blank project, you have to start...
Where to start?
What to test?
What not to test?
How much tests?
Where to start?
TDD: mmm
“If you need to test the insertion of an object into a collection and the collection is represented by an Array, with xUnit you should assert that the collection contains the object in the Array, but if the collection will change to another type of container, graph for example, the xUnit will fail, even if the behaviour is unchanged. “
TDD: mmmmmmmmm
in BDD you are not testing
you are describing what that classes will do,
so you can continue creating the class
Specify the Behaviour by Examples
not testing a class.
BDD :)
External behaviour - Story
Behat deals to have specifications that reflects the environment from the outside.Solve: Where to start, What to and not to test
Internal behaviour - Example
PHPSpec responds to the behaviour in the lower level, from the internal of the classes.
Solve all the TDD mmmmmmm
BDD :D
1 start from Scenario
2 write a story that fail
go to phpspec2 internal level
3 write a fail Example
4 get it green
5 refactor
go to behat external level
7 refactor
BDD the double cycle
"Spec BDD with phpspec
phpspec is a development tool, designed to help you achieve clean and working PHP code by using a technique derived from test-first development called (spec) behaviour driven developement, or SpecBDD."
1. Installation composer
2. Code the behaviour: WAIT
we have to talk the same language
{ "require-dev": { "phpspec/phpspec2": "*" }, "config": { "bin-dir": "bin" }, "autoload": {"psr-0": {"": "src"}}, "minimum-stability": "dev"}
LET’S CODE
In BDD you are going to 'Describe' the behaviour of a Class creating a `Spec` that will contain more Examples.
'example' is the class to write, before write the subject code.
'expectation' the behaviour that the subject code should have.
• Assertion becomes expectation.
• Test method becomes code example
• Test case becomes example group/Specification
DEFINITION
Not really coding, command lining :)
Now Code the examples ...
$ bin/phpspec desc FakeTwitterSpecification for FakeTwitter created in spec/FakeTwitter.php.
$ bin/phpspec run -v -f prettify
CODING TIME
BDD
BDD you're doing it wrong
I Code, than I specify
BDD you're doing it wrong
Cool I'm going to specify all my old
projects
BDD you're doing it wrong
I don't care about documentation and
acceptance.
1987 developer
I don't need unit tests, and I do not need to
specify
REFERENCES
- http://www.slideshare.net/bmabey/the-why-behind-tddbdd-and-the-how-with-rspec
- The RSpec Book: Behaviour-Driven Development with RSpec, Cucumber, and Friends
- http://www.slideshare.net/Robbert/bdd-rspec
- phpspec.net
- behat.org