In less than 12 months, Drupal 7 will be end-of-life and no longer supported. Plan your upgrade to Drupal 10 now.

Start with a failing test

When fixing a bug or adding a new feature using test-driven development, it's important to see the test fail first.

You should write your test so it doesn't pass by default or accidentally.

When creating data, such as users or nodes within tests, do so in a way that will force the test to fail, such as explicitly setting the title or published date into a non-default order.

When fixing a bug, write a test that represents the expected outcome when the bug is fixed. This confirms the bug exists and can be replicated.

Then, once the tests pass, you know the feature or fix is working and that it's because of your changes and not for any other reason.

- Oliver

P.S. If you're creating a new Drupal module, try my free Drupal module template.

Was this useful?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.