Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Unit tests for dummies

1.749 visualizaciones

Publicado el

Session from TYPO3 Developer Days 2016

Publicado en: Internet
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Unit tests for dummies

  1. 1. 0Nicole Cordes, T3DD16 - Unit tests for dummies Unit tests for dummies » Introduction » Basics » Hands on
  2. 2. 1Nicole Cordes, T3DD16 - Unit tests for dummies Introduction
  3. 3. 2Nicole Cordes, T3DD16 - Unit tests for dummies INTRODUCTION „Who is that girl?“ » Nicole Cordes » working at CPS-IT GmbH in Berlin » community activity since 2011 » Core and Security Team member » contributing to multiple public extensions » Slack: @IchHabRecht » Twitter: @IchHabRecht » Mail: typo3@cordes.co
  4. 4. 3Nicole Cordes, T3DD16 - Unit tests for dummies Basics
  5. 5. 4Nicole Cordes, T3DD16 - Unit tests for dummies BASICS „Why do I need unit tests?“ » verify your code does what you expect » manual testing is slow and cumbersome » automate testing is fast and cool » new changes don’t break existing functionality » keep others from breaking your code » safety net for refactorings
  6. 6. 5Nicole Cordes, T3DD16 - Unit tests for dummies BASICS „What are you talking about?“ test case test test test test assertion assertion assertion
  7. 7. 6Nicole Cordes, T3DD16 - Unit tests for dummies BASICS „What are you talking about?“ Processing of a test case » find all tests within the class » call dataProvider and store return values » call one test after another
  8. 8. 7Nicole Cordes, T3DD16 - Unit tests for dummies BASICS „What are you talking about?“ The life cycle of a test » create an object of the test class » call `setUp` method (protected!) » objects and environment can be prepared » call one test » call `tearDown` method (protected!) » objects and environment can be cleaned up
  9. 9. 8Nicole Cordes, T3DD16 - Unit tests for dummies Hands on
  10. 10. 9Nicole Cordes, T3DD16 - Unit tests for dummies USE CASE „ext_testing aka blog_example“
  11. 11. 10Nicole Cordes, T3DD16 - Unit tests for dummies RUNNING TESTS „How to run tests from CLI?“ » clone TYPO3 core » run `composer install` » use the cloned core for your development » run `typo3_src/bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml typo3conf/ext/ext_testing`
  12. 12. 11Nicole Cordes, T3DD16 - Unit tests for dummies RUNNING TESTS „How to run tests within PhpStorm?“ » set up PHP version for your project
  13. 13. 12Nicole Cordes, T3DD16 - Unit tests for dummies RUNNING TESTS „How to run tests within PhpStorm?“ » set up configuration
  14. 14. 13Nicole Cordes, T3DD16 - Unit tests for dummies RUNNING TESTS „How to run tests within PhpStorm?“ » add environment variable
  15. 15. 14Nicole Cordes, T3DD16 - Unit tests for dummies RUNNING TESTS „How to run tests within PhpStorm?“ » run test class or single test
  16. 16. 15Nicole Cordes, T3DD16 - Unit tests for dummies GENERATED TESTS „Why should generated tests be deleted?“ ControllerTest » due to Extbase all generated actions are very small » aggregate information and passing it to the view » test if data is visible (= assigned correctly) is not part of unit testing » acceptance testing » all those tests should be rewritten as functional tests (see you on Sunday )
  17. 17. 16Nicole Cordes, T3DD16 - Unit tests for dummies GENERATED TESTS „Why should generated tests be deleted?“ ModelTest » generated tests simply test getter and setter » no need to test getter and/or setter as long as they don’t implement functionality
  18. 18. 17Nicole Cordes, T3DD16 - Unit tests for dummies CODING REAL UNIT TESTS „How does real unit testing work?“ I » no own logic means no need for unit tests » we don’t need to test the core » tests for Extbase are done within the core » no need for unit tests doesn’t mean no need for other kinds of testing!
  19. 19. 18Nicole Cordes, T3DD16 - Unit tests for dummies CODING REAL UNIT TESTS „How does real unit testing work?“ II » add own logic » add test case for your class » add white- and blacklist tests » switch to dataProvider and think about edge cases
  20. 20. 19Nicole Cordes, T3DD16 - Unit tests for dummies CODING REAL UNIT TESTS „How does real unit testing work?“ III » add more advanced logic » add test case for your class » remove coupling to external dependencies (mocking) » define test expectations » switch mocks to prophecies to be more verbose on decoupling
  21. 21. 20Nicole Cordes, T3DD16 - Unit tests for dummies Thank you for your attention!

×