Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Behat from zero to hero - A practical guide to ...

Samuele
October 20, 2017

Behat from zero to hero - A practical guide to symfony integration and usage

Starting from behat introduction, we have explained some good practices for BDD testing in a symfony software. This presentation should be a quick "guide" for users that starts with Behat and also for those who want to fix their tests problems.

Samuele

October 20, 2017
Tweet

More Decks by Samuele

Other Decks in Programming

Transcript

  1. Behat from zero to hero “A practical guide to symfony

    integration and usage” Matteo Moretti - Samuele Lilli @SymfonyDayIt - 20 Ottobre 2017 - Milano
  2. Matteo Moretti | Samuele Lilli “WHY THE HELL THIS TEST

    IS BROKEN? I DIDN’T MODIFY THAT CODE”
  3. Matteo Moretti | Samuele Lilli “MMM, 10 MINUTES TO ADD

    A FEATURE. 2 HOURS TO FIX TESTS.”
  4. 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 ...
  5. 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 ...
  6. 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 ...
  7. 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 ...
  8. 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 ...
  9. 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 ...
  10. 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 ...
  11. Matteo Moretti | Samuele Lilli GIVEN - WHEN - THEN

    (AND, BUT) ARE KEYWORDS THAT MATCH PHP CODE AND EXECUTE IT. STEPS
  12. Matteo Moretti | Samuele Lilli COLLAPSE STEPS AS MUCH AS

    POSSIBLE UNLESS THESE GIVES YOU BUSINESS/STORY VALUE
  13. 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)
  14. Matteo Moretti | Samuele Lilli BEHAT → GHERKIN → FEATURES

    → STORIES (SCENARIOS) → STEPS → CONTEXTS
  15. Matteo Moretti | Samuele Lilli BEHAT → GHERKIN → FEATURES

    → STORIES (SCENARIOS) → STEPS → CONTEXTS
  16. Matteo Moretti | Samuele Lilli DIVIDE FEATURES AND CONTEXTS BY

    ACTIONS TO BE PERFORMED ON DOMAIN SUBJECTS
  17. 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
  18. Matteo Moretti | Samuele Lilli BROWSER CONTROLLER • aim to

    control a real browser • complex to configure • slow • JS/AJAX support
  19. Matteo Moretti | Samuele Lilli UI END-TO-END TESTS • BRITTLE

    • EXPENSIVE TO WRITE • TIME CONSUMING TO RUN • MORE AFFECTED BY NON-DETERMINISM
  20. Matteo Moretti | Samuele Lilli DO YOU REALLY NEED A

    REAL JS BROWSER? https://blog.eleven-labs.com/en/behat-structure-functional-tests/
  21. Matteo Moretti | Samuele Lilli FIXTURES DATA • NO FIXTURES

    (INTEGRATION TESTS) • LOAD FIXTURES AT RUNTIME • IN MEMORY DBMS (SQLITE)
  22. Matteo Moretti | Samuele Lilli PARALLELISM • SPEED UP PERFORMANCE

    • COMPLEX SETUP AND DEBUG DO YOU NEED IT?
  23. 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 {}"
  24. Matteo Moretti | Samuele Lilli CLI DEBUG • BEHAT CODE

    • APP CODE IF INTEGRATION TEST (NO UI) • APP CODE IF UI TESTS WITH BROWSER EMULATOR (BrowserKit)
  25. Matteo Moretti | Samuele Lilli WE ARE HIRING! (wanna join?

    ask us or visit our website) labs.madisoft.it