Successfully reported this slideshow.
Your SlideShare is downloading. ×

Behat from zero to hero: "a practical guide to Symfony integration and usage"

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 118 Ad
Advertisement

More Related Content

Advertisement

Behat from zero to hero: "a practical guide to Symfony integration and usage"

  1. 1. Behat from zero to hero “A practical guide to symfony integration and usage” Matteo Moretti - Samuele Lilli@SymfonyDayIt - 20 Ottobre 2017 - Milano
  2. 2. Matteo Moretti | Samuele Lilli WHO ARE WE? Matteo Moretti Samuele Lilli
  3. 3. Matteo Moretti | Samuele Lilli OUR EXPERIENCE
  4. 4. Matteo Moretti | Samuele Lilli OUR EXPERIENCE ON nuvola.madisoft.it https://symfony.com/showcase/191
  5. 5. Matteo Moretti | Samuele Lilli BEHAVIOUR DRIVEN DEVELOPMENT
  6. 6. Matteo Moretti | Samuele Lilli BEHAT
  7. 7. Matteo Moretti | Samuele Lilli A LONG TIME AGO ...
  8. 8. Matteo Moretti | Samuele Lilli
  9. 9. Matteo Moretti | Samuele Lilli
  10. 10. Matteo Moretti | Samuele Lilli TESTS ARE GREEN!
  11. 11. Matteo Moretti | Samuele Lilli BUT, SUDDENLY...
  12. 12. Matteo Moretti | Samuele Lilli AS SOON AS YOU ADD MORE TESTS...
  13. 13. Matteo Moretti | Samuele Lilli HARD TO MAINTAIN
  14. 14. Matteo Moretti | Samuele Lilli RANDOM FAILURES
  15. 15. Matteo Moretti | Samuele Lilli SLOW TESTS
  16. 16. Matteo Moretti | Samuele Lilli “WHY THE HELL THIS TEST IS BROKEN? I DIDN’T MODIFY THAT CODE”
  17. 17. Matteo Moretti | Samuele Lilli “MMM, 10 MINUTES TO ADD A FEATURE. 2 HOURS TO FIX TESTS.”
  18. 18. Matteo Moretti | Samuele Lilli
  19. 19. Matteo Moretti | Samuele Lilli
  20. 20. Matteo Moretti | Samuele Lilli WHAT IS BEHAT?
  21. 21. Matteo Moretti | Samuele Lilli IT’S A BDD TOOL!
  22. 22. Matteo Moretti | Samuele Lilli IT’S A STORY BDD TOOL!
  23. 23. Matteo Moretti | Samuele Lilli WHAT IS A STORY?
  24. 24. Matteo Moretti | Samuele Lilli HI! I’M A STORY!
  25. 25. Matteo Moretti | Samuele Lilli EXAMPLE OF HOW THE SYSTEM SHOULD BEHAVE DESCRIPTION OF A GIVEN REQUIREMENT IN UBIQUITOUS NATURAL LANGUAGE UNDERSTANDABLE BY ALL STAKEHOLDERS OF THE PROJECT ACCEPTANCE TEST DOCUMENTATION THAT NEVER GOES OUT TO DATE WRITTEN IN GHERKIN EXECUTABLE SPECIFICATION A STORY IS ...
  26. 26. Matteo Moretti | Samuele Lilli EXAMPLE OF HOW THE SYSTEM SHOULD BEHAVE DESCRIPTION OF A GIVEN REQUIREMENT IN UBIQUITOUS NATURAL LANGUAGE UNDERSTANDABLE BY ALL STAKEHOLDERS OF THE PROJECT ACCEPTANCE TEST DOCUMENTATION THAT NEVER GOES OUT TO DATE WRITTEN IN GHERKIN EXECUTABLE SPECIFICATION A STORY IS ...
  27. 27. Matteo Moretti | Samuele Lilli EXAMPLE OF HOW THE SYSTEM SHOULD BEHAVE DESCRIPTION OF A GIVEN REQUIREMENT IN UBIQUITOUS NATURAL LANGUAGE UNDERSTANDABLE BY ALL STAKEHOLDERS OF THE PROJECT ACCEPTANCE TEST DOCUMENTATION THAT NEVER GOES OUT TO DATE WRITTEN IN GHERKIN EXECUTABLE SPECIFICATION A STORY IS ...
  28. 28. Matteo Moretti | Samuele Lilli EXAMPLE OF HOW THE SYSTEM SHOULD BEHAVE DESCRIPTION OF A GIVEN REQUIREMENT IN UBIQUITOUS NATURAL LANGUAGE UNDERSTANDABLE BY ALL STAKEHOLDERS OF THE PROJECT ACCEPTANCE TEST DOCUMENTATION THAT NEVER GOES OUT TO DATE WRITTEN IN GHERKIN EXECUTABLE SPECIFICATION A STORY IS ...
  29. 29. Matteo Moretti | Samuele Lilli EXAMPLE OF HOW THE SYSTEM SHOULD BEHAVE DESCRIPTION OF A GIVEN REQUIREMENT IN UBIQUITOUS NATURAL LANGUAGE UNDERSTANDABLE BY ALL STAKEHOLDERS OF THE PROJECT ACCEPTANCE TEST DOCUMENTATION THAT NEVER GOES OUT TO DATE WRITTEN IN GHERKIN EXECUTABLE SPECIFICATION A STORY IS ...
  30. 30. Matteo Moretti | Samuele Lilli EXAMPLE OF HOW THE SYSTEM SHOULD BEHAVE DESCRIPTION OF A GIVEN REQUIREMENT IN UBIQUITOUS NATURAL LANGUAGE UNDERSTANDABLE BY ALL STAKEHOLDERS OF THE PROJECT ACCEPTANCE TEST DOCUMENTATION THAT NEVER GOES OUT TO DATE WRITTEN IN GHERKIN EXECUTABLE SPECIFICATION A STORY IS ...
  31. 31. Matteo Moretti | Samuele Lilli EXAMPLE OF HOW THE SYSTEM SHOULD BEHAVE DESCRIPTION OF A GIVEN REQUIREMENT IN UBIQUITOUS NATURAL LANGUAGE UNDERSTANDABLE BY ALL STAKEHOLDERS OF THE PROJECT ACCEPTANCE TEST DOCUMENTATION THAT NEVER GOES OUT TO DATE WRITTEN IN GHERKIN EXECUTABLE SPECIFICATION A STORY IS ...
  32. 32. Matteo Moretti | Samuele Lilli GHERKIN
  33. 33. Matteo Moretti | Samuele Lilli IT’S A LANGUAGE!
  34. 34. Matteo Moretti | Samuele Lilli IT’S A BUSINESS READABLE DOMAIN SPECIFIC LANGUAGE!
  35. 35. Matteo Moretti | Samuele Lilli LIKE YAML INDENTATION RULES PARSING
  36. 36. Matteo Moretti | Samuele Lilli STORIES ARE ORGANIZED IN FEATURES FILES (.feature)
  37. 37. Matteo Moretti | Samuele Lilli GIVEN - WHEN - THEN (AND, BUT) ARE KEYWORDS THAT MATCH PHP CODE AND EXECUTE IT. STEPS
  38. 38. Matteo Moretti | Samuele Lilli
  39. 39. Matteo Moretti | Samuele Lilli REGEX
  40. 40. Matteo Moretti | Samuele Lilli
  41. 41. Matteo Moretti | Samuele Lilli
  42. 42. Matteo Moretti | Samuele Lilli
  43. 43. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  44. 44. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  45. 45. Matteo Moretti | Samuele Lilli HOW A GOOD STORY LOOKS LIKE?
  46. 46. Matteo Moretti | Samuele Lilli FOCUS ON OUTPUT NOT INPUT X
  47. 47. Matteo Moretti | Samuele Lilli √ FOCUS ON OUTPUT NOT INPUT
  48. 48. Matteo Moretti | Samuele Lilli DON’T USE UI REFERENCES X
  49. 49. Matteo Moretti | Samuele Lilli DON’T USE UI REFERENCES √
  50. 50. Matteo Moretti | Samuele Lilli USE BACKGROUND
  51. 51. Matteo Moretti | Samuele Lilli USE TRANSFORMERS
  52. 52. Matteo Moretti | Samuele Lilli USE TRANSFORMERS
  53. 53. Matteo Moretti | Samuele Lilli COLLAPSE STEPS AS MUCH AS POSSIBLE UNLESS THESE GIVES YOU BUSINESS/STORY VALUE
  54. 54. Matteo Moretti | Samuele Lilli
  55. 55. Matteo Moretti | Samuele Lilli HOW MUCH DETAILS?
  56. 56. Matteo Moretti | Samuele Lilli “What many people don’t realize is that different levels of details are appropriate for different scenarios in the same system - sometimes in the same feature - depending on what it is they’re describing” (The cucumber book - Matt Wynne, Aslak Hellesoy)
  57. 57. Matteo Moretti | Samuele Lilli BEHAT → GHERKIN → FEATURES → STORIES (SCENARIOS) → STEPS → CONTEXTS
  58. 58. Matteo Moretti | Samuele Lilli BEHAT → GHERKIN → FEATURES → STORIES (SCENARIOS) → STEPS → CONTEXTS
  59. 59. Matteo Moretti | Samuele Lilli DIVIDE ET IMPERA
  60. 60. Matteo Moretti | Samuele Lilli ONE FEATURE PER .FEATURE FILE
  61. 61. Matteo Moretti | Samuele Lilli DIVIDE FEATURES AND CONTEXTS BY DOMAIN SUBJECT
  62. 62. Matteo Moretti | Samuele Lilli DIVIDE FEATURES AND CONTEXTS BY ACTIONS TO BE PERFORMED ON DOMAIN SUBJECTS
  63. 63. Matteo Moretti | Samuele Lilli
  64. 64. Matteo Moretti | Samuele Lilli
  65. 65. Matteo Moretti | Samuele Lilli UI
  66. 66. Matteo Moretti | Samuele Lilli HEADLESS BROWSER EMULATOR VS BROWSER CONTROLLER
  67. 67. Matteo Moretti | Samuele Lilli HEADLESS BROWSER EMULATOR ● pure HTTP spec implementations ● very simple to run and configure ● no need of a real browser: speed ● usually no JS/AJAX support
  68. 68. Matteo Moretti | Samuele Lilli BROWSER CONTROLLER ● aim to control a real browser ● complex to configure ● slow ● JS/AJAX support
  69. 69. Matteo Moretti | Samuele Lilli YOU MAY NEED BOTH OF THEM
  70. 70. Matteo Moretti | Samuele Lilli MINK http://mink.behat.org/en/latest/
  71. 71. Matteo Moretti | Samuele Lilli BEHAT PARSES SCENARIOS + MINK BROWSES THE WEB
  72. 72. Matteo Moretti | Samuele Lilli
  73. 73. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  74. 74. Matteo Moretti | Samuele Lilli HOW TO USE MINK FROM CONTEXT CLASSES?
  75. 75. Matteo Moretti | Samuele Lilli PAGE OBJECT PATTERN https://martinfowler.com/bliki/PageObject.html
  76. 76. Matteo Moretti | Samuele Lilli https://github.com/sensiolabs/BehatPageObjectExtension BEHAT PAGE OBJECT EXTENSION
  77. 77. Matteo Moretti | Samuele Lilli ASSERTIONS
  78. 78. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  79. 79. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  80. 80. Matteo Moretti | Samuele Lilli AJAX
  81. 81. Matteo Moretti | Samuele Lilli DON’T PULL YOUR TESTS WITH SLEEP() CALLS
  82. 82. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  83. 83. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  84. 84. Matteo Moretti | Samuele Lilli UI END-TO-END TESTS ● BRITTLE ● EXPENSIVE TO WRITE ● TIME CONSUMING TO RUN ● MORE AFFECTED BY NON-DETERMINISM
  85. 85. Matteo Moretti | Samuele Lilli
  86. 86. Matteo Moretti | Samuele Lilli https://martinfowler.com/bliki/TestPyramid.html
  87. 87. Matteo Moretti | Samuele Lilli DO YOU REALLY NEED A REAL JS BROWSER? https://blog.eleven-labs.com/en/behat-structure-functional-tests/
  88. 88. Matteo Moretti | Samuele Lilli STICK TO A BROWSER EMULATOR USE @javascript ONLY WHEN NEEDED
  89. 89. Matteo Moretti | Samuele Lilli FIXTURES DATA ● NO FIXTURES (INTEGRATION TESTS) ● LOAD FIXTURES AT RUNTIME ● IN MEMORY DBMS (SQLITE)
  90. 90. Matteo Moretti | Samuele Lilli PARALLELISM ● SPEED UP PERFORMANCE ● COMPLEX SETUP AND DEBUG DO YOU NEED IT?
  91. 91. Matteo Moretti | Samuele Lilli FASTEST https://github.com/liuggio/fastest bin/behat --list-scenarios --config tests/behat/behat.yml | bin/fastest -vv --process=4 "bin/behat --stop-on-failure --config tests/behat/behat.yml {}"
  92. 92. Matteo Moretti | Samuele Lilli ISSUES HARD TO MAINTAIN RANDOM FAILURES SLOW TESTS
  93. 93. Matteo Moretti | Samuele Lilli SAVE OUTPUT FOR FAILED TESTS
  94. 94. Matteo Moretti | Samuele Lilli DEBUG
  95. 95. Matteo Moretti | Samuele Lilli CLI DEBUG ● BEHAT CODE ● APP CODE IF INTEGRATION TEST (NO UI) ● APP CODE IF UI TESTS WITH BROWSER EMULATOR (BrowserKit)
  96. 96. Matteo Moretti | Samuele Lilli WEB DEBUG FOR APP CODE IF BROWSER CONTROLLER (SELENIUM)
  97. 97. Matteo Moretti | Samuele Lilli RECAP
  98. 98. Matteo Moretti | Samuele Lilli TREAT YOUR TEST CODE AS YOUR APP (PROD) CODE
  99. 99. Matteo Moretti | Samuele Lilli WRITE CLEAN, CONCISE AND WELL ORGANIZED FEATURES
  100. 100. Matteo Moretti | Samuele Lilli SPLIT YOUR CONTEXT CLASSES AND COMPOSE / REUSE THEM
  101. 101. Matteo Moretti | Samuele Lilli REMEMBER TEST PYRAMID FOCUS ON INTEGRATION LEVEL
  102. 102. Matteo Moretti | Samuele Lilli USE @javascript WISELY USE PAGE OBJECTS FOR UI
  103. 103. Matteo Moretti | Samuele Lilli THANK YOU
  104. 104. Matteo Moretti | Samuele Lilli WE ARE HIRING! (wanna join? ask us or visit our website) labs.madisoft.it
  105. 105. Matteo Moretti | Samuele Lilli https://joind.in/talk/707a1
  106. 106. QUESTIONS?

×