TDD (with FLOW3)

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    TDD (with FLOW3) - Presentation Transcript

    1. TDD (with FLOW3) Karsten Dambekalns <karsten@typo3.org> Robert Lemke <robert@typo3.org> Inspiring people to share
    2. What? Why? How? Integrate! Inspiring people to share
    3. Test first, code later
    4. Test first, code later Write tests for all your code • New features come with a test • Bugfixes come with a test Write tests before your code • Adding a feature means adding a test first • Fixing a bug means writing a test first Inspiring people to share
    5. Unit tests Unit tests are small programs that test your code They check • the result of methods against expected values • whether methods are (not) called as expected A test should • be well-named • check only one assertion Inspiring people to share
    6. Good tests Should be... • automated • self-contained • repeatable • thorough • small • talk about the domain Inspiring people to share
    7. Unit tests Unit tests are usually run with a test runner The xUnit family is most widespread PHPUnit does the job for PHP Inspiring people to share
    8. Tests aren’t the goal
    9. But you said...
    10. They make you feel good
    11. They make you feel good The tests make you • focus on your task • code exactly what you need • think from the outside • a better programmer* So what the tests do for you is the key * decoupling helps with testing, decoupled code is easier to maintain, easier is better - q.e.d. Inspiring people to share
    12. Reasons for TDD Feel more comfortable • Build confidence in your code • Reduce fear of change (Good) tests are (good) documentation Acts as safety net • Regression testing built in • Helps with refactoring Inspiring people to share
    13. D for Design Writing tests first is likely to improve your code Constant refactoring keeps code clean Unit testing ensure decoupling You only code what is really needed Inspiring people to share
    14. TDD in Practice Inspiring people to share
    15. The Mantra Inspiring people to share
    16. The Mantra Design Test Test Implement Inspiring people to share
    17. More testing Sometimes you need to test interaction with external systems, like database access A test should be small, encapsulated, stand-alone So how do you test database access? Inspiring people to share
    18. Mocks & stubs Mock objects allow you to use fake objects instead of real implementations Stubs can be used to return hard-coded results Using them is actually (somewhat) easy with PHPUnit Inspiring people to share
    19. Saving in TYPO3CR Assumptions / Background • The Session object has a save() method • It uses a Storage_Backend implementation to do the work • That implementation has methods like addNode(), updateNode() and deleteNode() You need to make sure those are used when calling save() Inspiring people to share
    20. No FLOW3? No TDD!
    21. No TDD without FLOW3 Without Dependency Injection you cannot really do unit testing Inspiring people to share
    22. Dependencies Problem: Classes explicitly refer to other classes: Inspiring people to share
    23. Dependencies Try to test this class: Inspiring people to share
    24. Dependencies Unit Testing: You want to test a small unit You don't want to test • The Simple File Logger • The Card Repository Inspiring people to share
    25. Dependencies Unit Testing: You want to test a small unit You want to test • if the action returns a string representation of the random card it gets from the repository Inspiring people to share
    26. Dependency Injection A class doesn't ask for the instance of another class but gets it injected This methodology is referred to as the \"Hollywood Principle\": \"Don't call us, we'll call you\" Enforces loose coupling and high cohesion Allows you to mock collaborators Makes you a better programmer Inspiring people to share
    27. Questions!
    28. Links & Literature Test-Driven Development By Example Kent Beck, Addison-Wesley Continuous Integration – Improving Software Quality and Reducing Risk Paul M. Duvall, Addison-Wesley xUnit Test Patterns – Refactoring Test Code Gerard Meszaros, Addison-Wesley Inspiring people to share
    29. Links & Literature FLOW3 http://flow3.typo3.org/ PHPUnit http://www.phpunit.de/ Hudson CI-Server https://hudson.dev.java.net/ TYPO3 Forge http://forge.typo3.org/ Inspiring people to share

    + Karsten DambekalnsKarsten Dambekalns, 2 years ago

    custom

    640 views, 0 favs, 0 embeds more stats

    An introduction to Test-Driven Development using FL more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 640
      • 640 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 10
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags