Alexey Korepov, an expert in Test Driven Development, discusses the importance of TDD in software development and its application in Drupal. The podcast covers topics such as resources for learning TDD, adapting to TDD in dev teams, environment setup, and special tools. The podcast also highlights the Test Helpers module for simplifying unit testing in Drupal projects.
Test-driven development helps identify bugs by reproducing them as failing unit tests and fixing them.
Setting up a local environment for test-driven development involves using tools like DDEV and Docker containers for isolated environments.
The Test Helpers module simplifies testing by checking actual data and service outcomes, aiding in convincing developers to adopt efficiently.
Deep dives
Test-driven Development Benefits
Test-driven development helps to identify bugs by reproducing them as failing unit tests and then fixing them. It ensures that all cases, including edge cases, are considered and tested. The approach focuses on requirements and inputs leading to stable, universal, and refactored code. Test-driven development promotes clean code and reduces regressions by enforcing continuous testing.
Local Environment Setup for Test Development
Setting up a local environment for test-driven development can involve using tools like DDEV with Drupal core testing instructions. Docker containers can provide isolated environments with specific PHP versions. Resources like GitLab containers and VS Code plugins showing code coverage can facilitate running and managing tests locally.
Incorporating Test Helpers into Core
The Test Helpers module provides infrastructure to simplify testing by checking actual data and service outcomes rather than just mocking results. While practical for custom projects and Contribute modules, integrating such helpers into Drupal core may face challenges due to its mixing of functional and unit testing logic. Providing examples, use cases, and benefits can aid in convincing developers to adopt test helpers efficiently.
Adapting Teams to Test-Driven Development
Adapting teams to test-driven development requires showcasing examples, highlighting benefits, and addressing concerns about additional work and discussions. Starting with small, beneficial steps and gradually incorporating test-driven development practices in project workflows can facilitate team adoption. Being flexible and choosing when to apply test-driven development ensures practical integration and enhances team efficiency.
Resources and Tools for Test-Driven Development
Resources like Drupal core testing documentation and tooling like PHP units can aid in setting up test-driven development locally. Utilizing VS Code with plugins for code coverage visibility enhances the testing process. Accessing GitLab containers and leveraging GitPod for Contribute modules streamline test execution and result review, contributing to efficient test-driven development practices.
Today we are talking about Test Driven Development, Why it’s important, and How it improves development with guest Alexey Korepov. We’ll also cover Test Helpers as our module of the week.
How old: created in Sep 2022 by today’s guest, Alexey Korepov
Versions available: 1.3.0 compatible with versions of Drupal 9.4 or newer, right up to Drupal 11
Maintainership
Actively maintained, latest release less than 3 months ago
Security coverage
Test coverage, would be ironic if it didn’t
API Documentation is available, linked from the project page
Number of open issues: 2 open issues, which are actually feature requests
Usage stats:
5 sites officially, but modules or sites can leverage Test Helpers without enabling it, and this usage is recommended, so the number is actually higher
Module features and usage
Provides a new container that automated tests can leverage to perform common tasks with much less code.
For example, you can create a user or a node with a single line of code
You can also mock more complex operations like an entityQuery or loadMultiple call, again with a single line of code
Traditionally, writing unit tests is more complicated because by design they run without fully bootstrapping Drupal
That means that your test needs to mock functions or services in the code you’re testing which can result in units tests being much longer than the code they’re testing
Test Helpers also allows your tests to leverage existing mocks and stubs for popular services
The project page also links to the recording and slides for a talk Alexey gave about Test Helpers at DrupalCon Pittsburgh last year, if you want to do a deeper dive
Get the Snipd podcast app
Unlock the knowledge in podcasts with the podcast player of the future.
AI-powered podcast player
Listen to all your favourite podcasts with AI-powered features
Discover highlights
Listen to the best highlights from the podcasts you love and dive into the full episode
Save any moment
Hear something you like? Tap your headphones to save it with AI-generated key takeaways
Share & Export
Send highlights to Twitter, WhatsApp or export them to Notion, Readwise & more
AI-powered podcast player
Listen to all your favourite podcasts with AI-powered features
Discover highlights
Listen to the best highlights from the podcasts you love and dive into the full episode