Your SlideShare is downloading. ×
Behaviour Testing and Continuous Integration with Drupal
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Behaviour Testing and Continuous Integration with Drupal


Published on

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Behaviour Testing and Continuous Integration with Drupal Smith Milner October 6th 2013 Pacific Northwest Drupal Summit
  • 2. Working Example affinitybridge/pnwds_behat Feel free to ask questions during the talk
  • 3. The Problem ● ● ● ● ● Large Complicated Project Multiple Clients using the same codebase Multiple Combinations of features installed Many Deployments Breakage would happen in other areas then the newest code being released
  • 4. From Stage Right Enter Behat.
  • 5. Jonathan Hedstrom and Melissa Anderson's session on Quality Assurance using Behat and the Drupal Extension?
  • 6. What is Behat? ● ● ● ● Behaviour Driven Development (BDD) The framework is written in PHP Write Tests fast Human Readable
  • 7. The Rest of the Stack ● ● ● Mink Browser Drivers used by Mink (goutte) Drupal Extension
  • 8. Drupal Extension ● ● Drupal Specific Step Definitions 3 Different Drivers ● ● ● ● ● blackbox drupal drush Cleans up In Active Development
  • 9. The Tests Scenario: anonymous users can't see user profiles. Given I am an anonymous user When I am viewing a "profile" node Then I should see "Access Denied"
  • 10. Gherkin Scenario: Short description of the tests goal Given some known state When I perform an action Then I expect a result
  • 11. Where are the tests? ● ● ● The tests are broken up into sets called Features (yup another one). They live in /features at the root of your testing stack. Don’t let your .features get too big.
  • 12. Annotations Tag feature sets or individual scenarios ● @javascript ● @api ● @drush ● @reinstall (custom)
  • 13. Annotations @javascript Scenario: Short description of the test goal Given some known state When I perform an action with javascript Then I expect a result
  • 14. Where the HAL is the code? What Powers the Steps?
  • 15. The Context Class: FeatureContext. php Lives in the same directory as in: test_root/features/bootstrap/FeatureContext.php Feature Context is a object created for each scenario. ● Allows sharing of variables between steps ● It extends a Context provided by Drupal Extension ●
  • 16. The Context Class: FeatureContext. php class FeatureContext extends DrupalContext { /** * @Given /^I run cron$/ */ public function iRunCron() { $this->getDriver()->runCron(); } }
  • 17. YAY We have Tests!
  • 18. Uh Oh They Always Fail
  • 19. Stay on Your Tests ● Run them often ● Make sure to capture the fragile functionality ● Take a look at broken tests right away
  • 20. But It’s So Hard! ● The tests break all the time! ● Other developers don’t run my tests! ● It can take a long time!
  • 21. From Stage Left Enter Travis CI.
  • 22. What is Travis CI? ● ● ● ● Continuous Integration service Integrates with Github post commit hooks Runs a build of your project every commit Reports Results (email, chat client, etc)
  • 23. Bob the Builder Where did the name Travis originate?
  • 24. How to Travis CI A configuration file is located in the project root. The .travis.yml file tells Travis CI how to set up an environment and how to run the tests. Every build runs from scratch on a fresh VM.
  • 25. Setup Tasks Include ● ● ● ● ● ● ● ● ● Create a MySQL Database Downloading Drush Building test framework with composer Setup Drupal with Drush Make Adding a files directory and settings.php Setup Selenium Standalone Server Install drupal (drush site-install) Run a server (drush runserver) Start your tests!
  • 26. Initial Hurdles ● ● ● Running javascript in a headless environment Extensive use of 3rd party libraries Testing configuration on Travis can take a long time
  • 27. Travis CI Reports Directly into our Chat Client Immediate announcement of how good you are at coding
  • 28. Travis CI Build History Lets you quickly review status of your build.
  • 29. This is me now
  • 30. Make it go Example Time!
  • 31. Questions?
  • 32. Thank You!