SlideShare a Scribd company logo
1 of 35
Download to read offline
Test all the things!
Automated testing with Drupal 8
27th Oct. 2016
Who am I?
In this session
● High level introduction of different testing concepts used in core and contrib
● How these concepts can be used to test bespoke Drupal site builds
● When to apply different types of tests to different situations
What are tests? Why test your code?
● Code that executes code
● Asserts a set of constraints
● Usually run on regular intervals
● See fewer bugs in production
● Make stakeholders (and developers!)
happy
● Release and deploy more confidently
● Write better code
● Refactor more confidently
How do we test code in Drupal 8?
● All tools found in Drupal core
● All based on PHPUnit
● Base classes help with interacting with Drupal
○ UnitTestCase
○ KernelTestBase
○ BrowserTestBase
○ JavascriptTestBase
○ … more on these later
● Useful for contrib, core and client projects
● Useful outside of Drupal?
PHPUnit
● Testing framework written in PHP
● Adopted by many other PHP frameworks
Basic anatomy of a PHPUnit test
● Live in the DrupalTestsmodule
namespace
● They usually extend a Drupal test base
● Setup method is run for every test method
● Each test method is prefixed with the word
“test”
● A test method contains a series of
assertions
● PHPUnit provides lots of assertion
methods
PHPUnit assertions
assertArrayHasKey
assertClassHasAttribute
assertArraySubset
assertClassHasStaticAttribute
assertContains
assertContainsOnly
assertContainsOnlyInstancesOf
assertCount
assertDirectoryExists
assertDirectoryIsReadable
assertDirectoryIsWritable
assertEmpty
assertEqualXMLStructure
assertEquals
assertFalse
assertFileEquals
assertFileExists
assertFileIsReadable
assertFileIsWritable
assertGreaterThan
assertGreaterThanOrEqual
assertInfinite
assertInstanceOf
assertInternalType
assertIsReadable
assertIsWritable
… and others (https://phpunit.de/manual/)
PHPUnit mocking
● Create classes your test code depends on
● Define exactly how they should behave
● Use as much or as little as the
dependency as you like
More on mocking:
https://phpunit.de/manual/current/en/test-doubles.html
PHPUnit @dataProvder
● Data providers run a test method with lots
of different inputs
● Allows you to name you test cases
● Helps cover lots of scenarios and quickly
identify what is broken
Running tests
● Configure all the environment variables
required to run tests
(https://www.drupal.org/docs/8/phpunit/running-phpunit-tests)
● Use the phpunit binary
● PHPStorm integration!
UnitTestCase
● Drupals unit testing base class
● Tests the behavior of a class in isolation
● Mock your dependencies, inject them
● No access to a Drupal bootstrap or database
● Very fast
● Test lots of inputs/outputs very quickly
Tests informing design
● Testable code is good code
● Clearly reveals your dependencies (some you never knew you had)
● Illustrates when you might have too many dependencies
● Encourages you to expose the minimum amount of information required
between classes
Real world examples
● Very simple unit test with
single assertion.
● Simple input/out scenario,
not mocking required.
● ~10ms per test case
Reference Table Formatter
List of Content Entities =>
Test doubles required for:
● EntityTypeInterface
● FieldDefinitionInterface
● FieldItemListInterface
● EntityManagerInterface
● EntityTypeInterface
● EntityStorageInterface
● EntityViewDisplayInterface
● RendererInterface
● Possibly a sign of bad design, should some
of the logic in the module be split into
different class?
● Pain to write and maintain, 150 lines of
code to mock dependencies.
● Possibly should have been an integration
test, testing against real world instances of
these dependencies.
Under the hood
There are limits...
KernelTestBase
● New concept to Drupal 8
● Write test code within a bootstrapped Drupal site
● Tests your codes integration with Drupal and other components
● Gives you access to Drupal APIs (entities, services, plugins etc)
● Still have access to all of the PHPUnit assertions and mocking
● Still pretty fast
● Install parts of Drupal required for the
test on demand
● Entity schema and module
configuration needs to be explicitly
installed
● Drupal content and configuration can
be created as part of the test
● Creates an entity
●
● Sets a field value and
● calls the view method
Runs through full entity
API system.
● ~3s per test case
●
● Introduces a web browser
● Functional, end-to-end testing, using a UI, simulating a user
● Write instructions for the web browser and make assertions about the UI
along the way
● Verbose output can show you a snapshot of the page at each step in the
test
● Slow to run
BrowserTestBase
Mink
● Pluggable browsers, one API
● Two browsers used in core (for now)
● Brings a whole library of assertions with it
● ...more at http://mink.behat.org/
The testing pyramid
● Write lots of unit tests
● Write integration tests
● Write some end-to-end UI tests
● Just a guide, common sense applies!
JavascriptTestBase
● BrowserTestBase but with JavaScript!
● Same assertion library as BTB
● Uses PhantomJS mink plugin
● Required for testing any kind of AJAX
● Test any JS UI interaction
○ Opening a lightbox
○ Scrolling the page
○ Resizing your window
○ Hovering over a menu
WebKit under the hood
Utility Traits
● Add useful functionality to
test classes
○ Create test content
○ Load entities
○ Custom more specific
assertions
● Extend KTB, BTB or JTB and
use the same methods.
Cheating setUp
● Run tests against a pre-setup site:
https://www.drupal.org/node/2793
445
● Useful for functional tests that
broadly cover a whole site
● Let CI do the heavy lifting
● WebTestBase, based on simpletest in Drupal 7
○ Still lots of core tests being converted
● The other KernelTestBase before it was based on phpunit
○ … when KTB was KTBTNG
Deprecated test classes
Consider not writing a test when...
● The code isn’t complex
● The test will only fails with false positives
● It has a maintenance cost with no benefit
Final thoughts
● Testing in Drupal 8 is awesome
● Write lots of tests
Questions?

More Related Content

What's hot

What's hot (20)

Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Xdebug and Drupal8 tests (PhpUnit and Simpletest)Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)
 
Testing PHP with Codeception
Testing PHP with CodeceptionTesting PHP with Codeception
Testing PHP with Codeception
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
 
Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with Codeception
 
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghAcceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup Edinburgh
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
Test automation with php codeception
Test automation with php codeceptionTest automation with php codeception
Test automation with php codeception
 
Five Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal SiteFive Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal Site
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Marcin Wasilczyk - Page objects with selenium
Marcin Wasilczyk - Page objects with seleniumMarcin Wasilczyk - Page objects with selenium
Marcin Wasilczyk - Page objects with selenium
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 

Viewers also liked

group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End allgroup 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
Alex Arndt
 
CV_Ranka_Papic_eng
CV_Ranka_Papic_engCV_Ranka_Papic_eng
CV_Ranka_Papic_eng
Ranka Papić
 

Viewers also liked (16)

Convencion colectivayipsybrito
Convencion colectivayipsybritoConvencion colectivayipsybrito
Convencion colectivayipsybrito
 
Instalación de sql server 2014
Instalación de sql server 2014Instalación de sql server 2014
Instalación de sql server 2014
 
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End allgroup 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
 
Обработка результатов энергоаудита (жилой дом в Минске по ул. Якубовского)
 Обработка результатов энергоаудита (жилой дом в Минске по ул. Якубовского) Обработка результатов энергоаудита (жилой дом в Минске по ул. Якубовского)
Обработка результатов энергоаудита (жилой дом в Минске по ул. Якубовского)
 
How to set up emergency numbers in AskoziaPBX - webinar 2016, English
How to set up emergency numbers in AskoziaPBX - webinar 2016, EnglishHow to set up emergency numbers in AskoziaPBX - webinar 2016, English
How to set up emergency numbers in AskoziaPBX - webinar 2016, English
 
Hotel_Bepoz
Hotel_BepozHotel_Bepoz
Hotel_Bepoz
 
Social psychology
Social psychology Social psychology
Social psychology
 
Unit plan power point
Unit plan power pointUnit plan power point
Unit plan power point
 
Составление энергетического паспорта здания. Определение класса энергетическ...
Составление энергетического паспорта здания. Определение класса энергетическ...Составление энергетического паспорта здания. Определение класса энергетическ...
Составление энергетического паспорта здания. Определение класса энергетическ...
 
Shotlist
ShotlistShotlist
Shotlist
 
Davey van der woert - Design Thinking
Davey van der woert - Design ThinkingDavey van der woert - Design Thinking
Davey van der woert - Design Thinking
 
Basic troubleshooting for Askozia IP PBX phone systems - webinar 2016, English
Basic troubleshooting for Askozia IP PBX phone systems - webinar 2016, EnglishBasic troubleshooting for Askozia IP PBX phone systems - webinar 2016, English
Basic troubleshooting for Askozia IP PBX phone systems - webinar 2016, English
 
CV_Ranka_Papic_eng
CV_Ranka_Papic_engCV_Ranka_Papic_eng
CV_Ranka_Papic_eng
 
TAGD Bylaws Proposed Changes
TAGD Bylaws Proposed ChangesTAGD Bylaws Proposed Changes
TAGD Bylaws Proposed Changes
 
Huelva powerpoint rosa
Huelva powerpoint rosaHuelva powerpoint rosa
Huelva powerpoint rosa
 
Edificaciones Industriales
Edificaciones IndustrialesEdificaciones Industriales
Edificaciones Industriales
 

Similar to Test all the things! Automated testing with Drupal 8

Behaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with DrupalBehaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with Drupal
smithmilner
 
Selenium Online Training.pdf
Selenium Online Training.pdfSelenium Online Training.pdf
Selenium Online Training.pdf
SpiritsoftsTraining
 

Similar to Test all the things! Automated testing with Drupal 8 (20)

Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven Infrastructure
 
Automation for developers
Automation for developersAutomation for developers
Automation for developers
 
DevOps presentation
DevOps presentationDevOps presentation
DevOps presentation
 
Moodle Development Best Pracitces
Moodle Development Best PracitcesMoodle Development Best Pracitces
Moodle Development Best Pracitces
 
TDD for joomla extensions
TDD for joomla extensionsTDD for joomla extensions
TDD for joomla extensions
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
Write unit test from scratch
Write unit test from scratchWrite unit test from scratch
Write unit test from scratch
 
Quality for developers
Quality for developersQuality for developers
Quality for developers
 
Cypress Testing.pptx
Cypress Testing.pptxCypress Testing.pptx
Cypress Testing.pptx
 
Behaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with DrupalBehaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with Drupal
 
Selenium Online Training.pdf
Selenium Online Training.pdfSelenium Online Training.pdf
Selenium Online Training.pdf
 
Continuous Integration In Php
Continuous Integration In PhpContinuous Integration In Php
Continuous Integration In Php
 
Expedia 3x3 presentation
Expedia 3x3 presentationExpedia 3x3 presentation
Expedia 3x3 presentation
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Selenium Online Training.pdf
Selenium Online Training.pdfSelenium Online Training.pdf
Selenium Online Training.pdf
 
Selenium Online Training.pdf
Selenium Online Training.pdfSelenium Online Training.pdf
Selenium Online Training.pdf
 
Selenium Online Training.pdf
Selenium Online Training.pdfSelenium Online Training.pdf
Selenium Online Training.pdf
 
Selenium Online Training.pdf
Selenium Online Training.pdfSelenium Online Training.pdf
Selenium Online Training.pdf
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Test all the things! Automated testing with Drupal 8

  • 1.
  • 2. Test all the things! Automated testing with Drupal 8 27th Oct. 2016
  • 4. In this session ● High level introduction of different testing concepts used in core and contrib ● How these concepts can be used to test bespoke Drupal site builds ● When to apply different types of tests to different situations
  • 5. What are tests? Why test your code? ● Code that executes code ● Asserts a set of constraints ● Usually run on regular intervals ● See fewer bugs in production ● Make stakeholders (and developers!) happy ● Release and deploy more confidently ● Write better code ● Refactor more confidently
  • 6. How do we test code in Drupal 8? ● All tools found in Drupal core ● All based on PHPUnit ● Base classes help with interacting with Drupal ○ UnitTestCase ○ KernelTestBase ○ BrowserTestBase ○ JavascriptTestBase ○ … more on these later ● Useful for contrib, core and client projects ● Useful outside of Drupal?
  • 7. PHPUnit ● Testing framework written in PHP ● Adopted by many other PHP frameworks
  • 8. Basic anatomy of a PHPUnit test ● Live in the DrupalTestsmodule namespace ● They usually extend a Drupal test base ● Setup method is run for every test method ● Each test method is prefixed with the word “test” ● A test method contains a series of assertions ● PHPUnit provides lots of assertion methods
  • 10. PHPUnit mocking ● Create classes your test code depends on ● Define exactly how they should behave ● Use as much or as little as the dependency as you like More on mocking: https://phpunit.de/manual/current/en/test-doubles.html
  • 11. PHPUnit @dataProvder ● Data providers run a test method with lots of different inputs ● Allows you to name you test cases ● Helps cover lots of scenarios and quickly identify what is broken
  • 12. Running tests ● Configure all the environment variables required to run tests (https://www.drupal.org/docs/8/phpunit/running-phpunit-tests) ● Use the phpunit binary ● PHPStorm integration!
  • 13. UnitTestCase ● Drupals unit testing base class ● Tests the behavior of a class in isolation ● Mock your dependencies, inject them ● No access to a Drupal bootstrap or database ● Very fast ● Test lots of inputs/outputs very quickly
  • 14. Tests informing design ● Testable code is good code ● Clearly reveals your dependencies (some you never knew you had) ● Illustrates when you might have too many dependencies ● Encourages you to expose the minimum amount of information required between classes
  • 16. ● Very simple unit test with single assertion. ● Simple input/out scenario, not mocking required. ● ~10ms per test case
  • 17. Reference Table Formatter List of Content Entities =>
  • 18.
  • 19. Test doubles required for: ● EntityTypeInterface ● FieldDefinitionInterface ● FieldItemListInterface ● EntityManagerInterface ● EntityTypeInterface ● EntityStorageInterface ● EntityViewDisplayInterface ● RendererInterface ● Possibly a sign of bad design, should some of the logic in the module be split into different class? ● Pain to write and maintain, 150 lines of code to mock dependencies. ● Possibly should have been an integration test, testing against real world instances of these dependencies. Under the hood
  • 21. KernelTestBase ● New concept to Drupal 8 ● Write test code within a bootstrapped Drupal site ● Tests your codes integration with Drupal and other components ● Gives you access to Drupal APIs (entities, services, plugins etc) ● Still have access to all of the PHPUnit assertions and mocking ● Still pretty fast
  • 22. ● Install parts of Drupal required for the test on demand ● Entity schema and module configuration needs to be explicitly installed ● Drupal content and configuration can be created as part of the test
  • 23. ● Creates an entity ● ● Sets a field value and ● calls the view method Runs through full entity API system. ● ~3s per test case ●
  • 24. ● Introduces a web browser ● Functional, end-to-end testing, using a UI, simulating a user ● Write instructions for the web browser and make assertions about the UI along the way ● Verbose output can show you a snapshot of the page at each step in the test ● Slow to run BrowserTestBase
  • 25. Mink ● Pluggable browsers, one API ● Two browsers used in core (for now) ● Brings a whole library of assertions with it ● ...more at http://mink.behat.org/
  • 26. The testing pyramid ● Write lots of unit tests ● Write integration tests ● Write some end-to-end UI tests ● Just a guide, common sense applies!
  • 27. JavascriptTestBase ● BrowserTestBase but with JavaScript! ● Same assertion library as BTB ● Uses PhantomJS mink plugin ● Required for testing any kind of AJAX ● Test any JS UI interaction ○ Opening a lightbox ○ Scrolling the page ○ Resizing your window ○ Hovering over a menu
  • 28.
  • 30. Utility Traits ● Add useful functionality to test classes ○ Create test content ○ Load entities ○ Custom more specific assertions ● Extend KTB, BTB or JTB and use the same methods.
  • 31. Cheating setUp ● Run tests against a pre-setup site: https://www.drupal.org/node/2793 445 ● Useful for functional tests that broadly cover a whole site ● Let CI do the heavy lifting
  • 32. ● WebTestBase, based on simpletest in Drupal 7 ○ Still lots of core tests being converted ● The other KernelTestBase before it was based on phpunit ○ … when KTB was KTBTNG Deprecated test classes
  • 33. Consider not writing a test when... ● The code isn’t complex ● The test will only fails with false positives ● It has a maintenance cost with no benefit
  • 34. Final thoughts ● Testing in Drupal 8 is awesome ● Write lots of tests