A Sweet Test Suite DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
A Sweet Test Sweet Dan Gurin Engineer @CivicActions Drupal Camp Asheville Organizer Twitter @dgurin dangur on github, LinkedIn, www, Slack... DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Test Driven Development 1. Behavior-Driven Development (BDD) with Behat 2. Visual Regression Testing 3. Unit testing with PHPUnit DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Behat Drupal Extension ● Plain language ● Common scenarios ● Changes & updates ● Extensible extension DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Tags ● Driver @api @javascript ● Groups @database @form ● Hooks ○ @beforeNodeCreate ○ @AfterScenario DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Drivers Blackbox No privileges Drush @api Can run on a different server Drupal @api More step definitions DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat machine_name * Machine Name Generated by JavaScript, so without PhantonJS & @javascript, becomes an additional required field. DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Comments ● # <- Anything on a line followed by a hashtag ● Use PhpStorm? Control or Command Slash / to comment out line(s) DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Background & Tables ● Applies to all Scenarios ● Create many items DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Contexts ● Drupal - users, terms, and nodes ○ DrupalRaw - functionality ● Mink - regions and forms ● Markup - tags, classes, & attributes ● Message - notice, warning, & error ● Drush - call commands directly DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Custom Contexts FeatureContext.php file CustomContext class 1. Write the step 2. Run the test (it will fail) 3. Copy the generated snippet DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Custom Contexts DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Custom Contexts DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Custom Contexts 1. Delete exception 2. Add code 3. Test again and see if it worked DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Debugging ● Steps ○ print current url ○ print last response ● print_r($variable); DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat D8 extension extension github.com/nuvoleweb/drupal-behat Autocomplete, CKEditor, Chosen, Content, Drupal, Menu, Position, Raw, Responsive, Screenshot, Select, ServiceContainer, Taxonomy, Visibility DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Sub contexts ● Contrib & Custom projects ● Modules ● Themes DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Behavior Driven Development with Behat Contributing ● Behat Drupal Extension ● https://github.com/Behat/Behat/ blob/master/CONTRIBUTING.md ● http://mink.behat.org/en/latest/c ontributing.html DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Test Driven Development 1. Behavior-Driven Development (BDD) with Behat 2. Visual Regression Testing 3. Unit testing with PHPUnit DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Visual Regression Testing with WebdriverCSS Visual Regression Testing ● Good coverage ● Display changes ● Great for updates DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Visual Regression Testing with WebdriverCSS Visual Regression Testing DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Visual Regression Testing with WebdriverCSS Intersection over Union IoU DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Test Driven Development 1. Behavior-Driven Development (BDD) with Behat 2. Visual Regression Testing 3. Unit testing with PHPUnit DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Drupal 8 PHPUnit Suites Name Extend State Requires Unit UnitTestCase None Code Kernel KernelTestBase Bootstrapped Database Functional BrowserTestBase Booted Webserver Javascript JavascriptTestBase Booted PhantomJS DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Unit DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Assertions ● Equals ● Same ● True / False ● PHPUnit Documentation Appendix A https://phpunit.de/manual/current/en/phpunit-book.html#appendixes.assertions DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Kernel ● Setup ● Config DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Setup ● Beginning of class ● Applies to all test functions ● Set up the parent first DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Install ● Schema ● Entity schema ● Configuration DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit setUp DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Install Fields ● Get from configuration management ● Create ○ Storage ○ Field DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Enable modules DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Functional ● Enable modules ● Paths! ● Web assert DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Functional DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit JavaScript ● executeScript / evaluateScript ● switchToIFrame ● keyDown ● resizeWindow ● wait DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit JavascriptTestBase ● createScreenshot ● getDrupalSettings DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit JavaScript Assertions ● assertElement(Not)Visible ● assertJsCondition DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit assertSession ● waitFor AjaxToFinish, Button, Element(Visible), Field, Link ● waitOnAutocomplete ● responseContains ● isVisible DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Test Doubles Return a value without the object DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Mock Objects DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Traits ● Code reuse in many classes ● Groups sets of methods ● Can not be instantiated DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Reflection Trait Test protected / private methods DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Trait in action DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Data Providers ● Run same test with different datasets DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Data Providers ● Named dataset via associative array DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Unit Testing with PHPUnit Debugging ● print_r($whatEver); ● Screenshots ● Reports ● Error/failure messages DrupalCamp Atlanta | A Sweet Test Suite | Dan Gurin | @dgurin | @CIVICACTIONS
Recommend
More recommend