7 lines
1.4 KiB
Markdown
7 lines
1.4 KiB
Markdown
---
|
|
date: 2025-05-15
|
|
title: Don't dump. Write a test.
|
|
permalink: /daily/2025/05/15/dont-dump-write-test
|
|
---
|
|
|
|
<p>How often do you use functions like <code>var_dump</code>, <code>dump</code>, <code>dd</code> or <code>console.log</code> to debug an issue?</p><p>You want to check the type or value of something, so you add the debug code and reload the page.</p><p>If you don't resolve it on the first attempt, you change it or add more debugging lines which, hopefully, you'll remember to clean up before committing your code.</p><p>This is a time-consuming process, especially if the code you're debugging isn't easy to trigger.</p><p>Maybe it only happens when you've submitted a long form, so you need to manually complete the form each time you want to debug it, if certain steps have already happened or the application state is a certain way.</p><p>Instead, consider writing an automated test.</p><p>They can be run when needed without needing to manually fill in forms or complete complex steps, and become a permanent part of the codebase rather than something that's only added temporarily whilst debugging.</p><p>They can be run manually by Developers, automatically in a CI pipeline and serve as documentation and examples.</p><p>Don't dump. Test.</p><p>P.S. If you want to learn how to write automated tests in Drupal, subscribe to <a href="http://localhost:8888/atdc">my free 10-day email course</a>.</p>
|