0
IT’S ALL ABOUT BEHAVIOUR
-ALSO IN PHP@liuggio
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 ...
TDD: THE INFINTE CYCLE

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 dup...
TDD: mmm
If you have a blank project, you have to start...
Where to start?
What to test?
What not to test?
How much tests?...
TDD: mmmmmmmmm
“If you need to test the insertion of an object into a
collection and the collection is represented by an
A...
BDD :)
in BDD you are not testing
you are describing what that classes will do,
so you can continue creating the class
Spe...
BDD :D
External behaviour - Story
Behat deals to have specifications that reflects
the environment from the outside.
Solve...
BDD the double cycle
1 start from Scenario
2 write a story that fail
go to phpspec2 internal level

3 write a fail Example...
"Spec BDD with phpspec
phpspec is a development tool, designed to help you achieve
clean and working PHP code by using a t...
LET’S CODE
1. Installation composer

{
"require-dev": {
"phpspec/phpspec2": "*"
},
"config": {
"bin-dir": "bin"
},
"autolo...
DEFINITION
In BDD you are going to 'Describe' the behaviour of a Class
creating a `Spec` that will contain more Examples.
...
CODING TIME
Not really coding, command lining :)
$ bin/phpspec desc FakeTwitter
Specification for FakeTwitter created in s...
BDD
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.

BDD you're doing it wrong
I don't need unit tests,
and I do not need to
specify

1987 developer
REFERENCES
- http://www.slideshare.net/bmabey/the-why-behind-tddbdd-and-the-how-with-rspec
- The RSpec Book: Behaviour-Dri...
Upcoming SlideShare
Loading in...5
×

It's all about behaviour, also in php - phpspec

3,817

Published on

BDD is not only for rubists :)

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,817
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
13
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "It's all about behaviour, also in php - phpspec"

  1. 1. IT’S ALL ABOUT BEHAVIOUR -ALSO IN PHP@liuggio PUG-ROMA 26-02-2013
  2. 2. WHY WE DO TESTS? > refactor > automation > verification > ??
  3. 3. 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
  4. 4. TDD: THE INFINTE CYCLE RED GREEN REFACTOR
  5. 5. 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
  6. 6. TDD: mmm 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?
  7. 7. TDD: mmmmmmmmm “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. “
  8. 8. BDD :) 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.
  9. 9. BDD :D 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
  10. 10. BDD the double cycle 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
  11. 11. "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."
  12. 12. LET’S CODE 1. Installation composer { "require-dev": { "phpspec/phpspec2": "*" }, "config": { "bin-dir": "bin" }, "autoload": {"psr-0": {"": "src"}}, "minimum-stability": "dev" } 2. Code the behaviour: WAIT we have to talk the same language
  13. 13. DEFINITION 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
  14. 14. CODING TIME Not really coding, command lining :) $ bin/phpspec desc FakeTwitter Specification for FakeTwitter created in spec/FakeTwitter.php. Now Code the examples ... $ bin/phpspec run -v -f prettify
  15. 15. BDD
  16. 16. I Code, than I specify BDD you're doing it wrong
  17. 17. Cool I'm going to specify all my old projects BDD you're doing it wrong
  18. 18. I don't care about documentation and acceptance. BDD you're doing it wrong
  19. 19. I don't need unit tests, and I do not need to specify 1987 developer
  20. 20. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×