Behat

1,125 views

Published on

Published in: Technology
  • Be the first to comment

Behat

  1. 1. Behat©  Александр  ШвецSunday, June 9, 13
  2. 2. Или как писать тесты, от вида которыхне хочеться застрелиться.Sunday, June 9, 13
  3. 3. Sunday, June 9, 13
  4. 4. Sunday, June 9, 13
  5. 5. Большая часть стоимостиразработки ПО складываетсяиз задержек обратной связиSunday, June 9, 13
  6. 6. Давайте ихуменьшим!Sunday, June 9, 13
  7. 7. Sunday, June 9, 13
  8. 8. Sunday, June 9, 13
  9. 9. Sunday, June 9, 13
  10. 10. Sunday, June 9, 13
  11. 11. Sunday, June 9, 13
  12. 12. Sunday, June 9, 13
  13. 13. StoryBDDSunday, June 9, 13
  14. 14. StoryBDD может выглядетькак «функциональное TDD»,для людей, не практикующихBDD, но это не так.Sunday, June 9, 13
  15. 15. Sunday, June 9, 13
  16. 16. Мы не тестируем, что приложениефункционирует так, как мы(разработчики) ожидаем, чтобы оноработало.Sunday, June 9, 13
  17. 17. Мы не тестируем, что приложениефункционирует так, как мы(разработчики) ожидаем, чтобы оноработало.Вместо этого, мы тестируем, чтоприложение соотвествует бизнесожиданиям клиента.Sunday, June 9, 13
  18. 18. Sunday, June 9, 13
  19. 19. Некоторые приложения слегкостью соответствуютожиданиям разработчиков, новсе же, лежат очень далеко отожиданий бизнеса.Sunday, June 9, 13
  20. 20. Sunday, June 9, 13
  21. 21. Вы можете думать о StoryBDD,как о способе обучитьклиентов тестированию.Sunday, June 9, 13
  22. 22. Вы можете думать о StoryBDD,как о способе обучитьклиентов тестированию.В действительности, этоинструмент, который можетобучить вас бизнесу клиента.Sunday, June 9, 13
  23. 23. Погружение вбизнес-процессыклиентаSunday, June 9, 13
  24. 24. 3 уровня описанияпроцессовSunday, June 9, 13
  25. 25. Sunday, June 9, 13
  26. 26. (повествовательный)narrative1(возможные сценарии)possible scenarios2(детали сценариев)scenario details3Sunday, June 9, 13
  27. 27. (возможные сценарии)possible scenarios2(детали сценариев)scenario details3Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateSunday, June 9, 13
  28. 28. (детали сценариев)scenario details3Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateScenario: Successfully authenticatingwith correct credentialsSunday, June 9, 13
  29. 29. Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateScenario: Successfully authenticatingwith correct credentialsGiven there is a user “neochief” with password “123”And I am on the login pageWhen I fill in “username” with “neochief”And I fill in “password” with “123”And I press “login”Then I should see “Hello, neochief”Sunday, June 9, 13
  30. 30. Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateScenario: Successfully authenticatingwith correct credentialsSunday, June 9, 13
  31. 31. Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateScenario: Successfully authenticatingwith correct credentialsSunday, June 9, 13
  32. 32. Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateScenario: Successfully authenticatingwith correct credentialsScenario: Can not authenticate withwrong credentialsScenario: Blocked user can notauthenticate, even with correctcredentialsSunday, June 9, 13
  33. 33. Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateSunday, June 9, 13
  34. 34. Feature: AuthorizationIn order to get access to the shopping historyAs a frequent buyerI need to be able to authenticateUser story?Sunday, June 9, 13
  35. 35. Sunday, June 9, 13
  36. 36. StoryBDD гарантирует, чторазработчики понимают бизнесклиента на том же уровне, что и самклиент.А иногда помогает и самому клиентуразобраться в его бизнесе.Sunday, June 9, 13
  37. 37. Как именно?Sunday, June 9, 13
  38. 38. Заставляет отвечать навопросы:Sunday, June 9, 13
  39. 39. Заставляет отвечать навопросы:• Для кого?Sunday, June 9, 13
  40. 40. Заставляет отвечать навопросы:• Для кого?• Что делать?Sunday, June 9, 13
  41. 41. Заставляет отвечать навопросы:• Для кого?• Что делать?• Как делать?Sunday, June 9, 13
  42. 42. Заставляет отвечать навопросы:• Для кого?• Что делать?• Как делать?•Зачем?Sunday, June 9, 13
  43. 43. Behathttp://behat.org/Sunday, June 9, 13
  44. 44. Что делает Behat?• Превращает сценарии StoryBDD в PHPкод (например, команды Selenium).• Исполняет этот код.• Выводит отчеты о тестировании.Sunday, June 9, 13
  45. 45. Инсталируем$> vim composer.json{“require-dev”: {“behat/behat”:“~2.4.5”,},“config”: { “bin-dir”:“bin/” }}$> curl http://getcomposer.org/installer | php$> php composer.phar install --devSunday, June 9, 13
  46. 46. Инициализируем+d features+d features/bootstrap+f features/bootstrap/FeatureContext.php$> bin/behat --initSunday, June 9, 13
  47. 47. <?phpuse BehatBehatContextClosuredContextInterface,BehatBehatContextTranslatedContextInterface,BehatBehatContextBehatContext,BehatBehatExceptionPendingException;use BehatGherkinNodePyStringNode,BehatGherkinNodeTableNode;class FeatureContext extends BehatContext{public function __construct(array $parameters){// Initialize your context here}}Sunday, June 9, 13
  48. 48. ...You can implement step definitions for undefined steps with thesesnippets:/*** @When /^I fill in “([^”]+)” with “([^”]+)”$/*/public function iFillInWith($val1, $val2){throw new PendingException();}...$> bin/behatПишем реализациюSunday, June 9, 13
  49. 49. ...You can implement step definitions for undefined steps with thesesnippets:/*** @When /^I fill in “([^”]+)” with “([^”]+)”$/*/public function iFillInWith($val1, $val2){throw new PendingException();}...$> bin/behatSunday, June 9, 13
  50. 50. $> bin/behat --append-snippetsSunday, June 9, 13
  51. 51. /*** @Given /^I am on homepage$/*/public function iAmOnHomepage(){throw new PendingException();}/*** @Given /^I follow “sign up”$/*/public function iFollowSignUp(){throw new PendingException();}/*** @When /^I fill in “([^”]+)” with “([^”]+)”$/*/public function iFillInWith($val1, $val2){throw new PendingException();}FeatureContext.phpSunday, June 9, 13
  52. 52. Feature: registrationin order to maintain my shopping historyas a site visitori need to be able to register on this siteScenario: Successful registration when visitor provides all therequired infoGiven I am on homepageTODO: write pending definitionAnd I follow “sign up”When I fill in “email” with “linkedin@example.com”And I fill in “username” with “linkedin”And I fill in “password” with “sha1_without_salt”And I press “register”Then I should see “You have been successfully registered”And I should be on homepage1 scenario (1 pending)8 steps (7 skipped, 1 pending)0m0.015s$> bin/behat ВыполняемSunday, June 9, 13
  53. 53. /*** @Given /^I am on homepage$/*/public function iAmOnHomepage(){$crawler = new SomeCrawlerLibCrawler();$crawler->goto(“http://localhost:8080/”);if (200 !== $crawler->getCurrentStatusCode()){throw new RuntimeException(‘Can not open homepage’);}}FeatureContext.phpSunday, June 9, 13
  54. 54. Feature: registrationin order to maintain my shopping historyas a site visitori need to be able to register on this siteScenario: Successful registration when visitor provides all therequired infoGiven I am on homepageCan not open homepageAnd I follow “sign up”When I fill in “email” with “linkedin@example.com”And I fill in “username” with “linkedin”And I fill in “password” with “sha1_without_salt”And I press “register”Then I should see “You have been successfully registered”And I should be on homepage1 scenario (1 FAILED)8 steps (7 skipped, 1 FAILED)0m0.015s$> bin/behatSunday, June 9, 13
  55. 55. Feature: registrationin order to maintain my shopping historyas a site visitori need to be able to register on this siteScenario: Successful registration when visitor provides all therequired infoGiven I am on homepageAnd I follow “sign up”TODO: write pending definitionWhen I fill in “email” with “linkedin@example.com”And I fill in “username” with “linkedin”And I fill in “password” with “sha1_without_salt”And I press “register”Then I should see “You have been successfully registered”And I should be on homepage1 scenario (1 pending)8 steps (1 passed, 7 skipped, 1 pending)0m0.015s$> bin/behatSunday, June 9, 13
  56. 56. Drupal?• Drupal Extension (https://drupal.org/project/drupalextension)• Инфраструктура Drupal.org тестируетсяпри помощи Behat (https://drupal.org/project/doobie).• http://groups.drupal.org/behatSunday, June 9, 13
  57. 57. Вопросы?Александр ШвецE-mail: neochief@shvetsgroup.comSkype: neo.chiefwww.shvetsgroup.comSunday, June 9, 13

×