Unit tests in Drupal

Tips on getting started with test-driven development for cleaner, faster code

CivicActions
CivicActions

--

Lines of code on a screen
Photo by Markus Spiske on Unsplash

At DrupalCon Global 2020, CivicActions Engineer Eric Napier and Open Data Expert Gerardo Gonalez discussed Test-Driven Development (or TDD) for writing clean code that works in Drupal. TDD is an approach to software creation that requires engineers to write tests for code that doesn’t yet exist, in order to create a continuous feedback loop between the code and the developer(s).

TDD first came about as a response to outdated and inefficient software development processes such as Waterfall. While it might feel unnatural to test something first without knowing whether or not it will work, this presentation aims to take the fear out of Test Driven Development. Watch as our engineers give live demos of this process, along with the following:

  • The history of TDD (Test-Driven Development)
  • Why TDD works
  • How to write Awesome Unit Tests
  • How to apply TDD in Drupal
  • When to use different types of unit tests
Watch “Unit Tests in Drupal” from DrupalCon Global 2020

“At its core, TDD is a very simple process: write a test first, see the test fails, write just enough code to make the test pass, and then let the test drive your workflow.” — Eric

Highlights

  • 1:00 — Overview of TDD and how it was first used by NASA on Project Mercury
  • 7:03 — How CivicActions uses Agile and TDD practices to bring value to client work
  • 9:03 — The two rules and three phases of TDD
  • 10:36 — How to run tests using PHPUnit
  • 11:17 — Creating the memory store
  • 12:33 — Retrieving the strings from the store
  • 13:37 — How to run a completed test (and what to do when it fails)
  • 17:45 — Viewer participation helps a test pass when an unknown issue arises
  • 25:43 — Defining and demonstrating the difference between Solitary and Sociable tests
  • 30:00 — Gerardo’s Mockchain Library, and how it helps users working in PHPUnit
  • 35:37 — How to run these tests in Drupal, and the common challenges you might face
  • 40:10 — Live demo test in Drupal, and the results

Resources

Connect with Eric Napier

Connect with Gerardo Gonalez

--

--

CivicActions
CivicActions

Building digital services that work for everyone.