{ "uuid": [ { "value": "5e7e771b-259f-4255-b45d-e8c81a7ae673" } ], "langcode": [ { "value": "en" } ], "type": [ { "target_id": "daily_email", "target_type": "node_type", "target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7" } ], "revision_timestamp": [ { "value": "2025-04-16T14:13:05+00:00" } ], "revision_uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "revision_log": [], "status": [ { "value": true } ], "uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "title": [ { "value": "Tests are living documentation\n" } ], "created": [ { "value": "2022-12-30T00:00:00+00:00" } ], "changed": [ { "value": "2025-04-16T14:13:05+00:00" } ], "promote": [ { "value": false } ], "sticky": [ { "value": false } ], "default_langcode": [ { "value": true } ], "revision_translation_affected": [ { "value": true } ], "path": [ { "alias": "\/daily\/2022\/12\/30\/tests-are-living-documentation", "langcode": "en" } ], "body": [ { "value": "\n
Today I was working on a project and made a one-line change that updated a single value within an API response.<\/p>\n\n
Unexpectedly, it caused a test to fail. The API response returned a 500 status code instead of the expected 201 code.<\/p>\n\n
I reverted the change locally and ensured that the test passed again, so I knew it was causing the failure.<\/p>\n\n
The change was removing a hard-coded part of a URL to a dynamic one, using Drupal's I was retrieving a value from it, but as there was no value being set within the test, it was returning a null value and causing the 500 error code.<\/p>\n\n To fix the test failure, I needed to learn how to set a Settings value within a test.<\/p>\n\n To do this, I looked for and found the test for the Settings class itself. I saw how it was being set there, did the same in my test, fixed the failure and got my test passing again.<\/p>\n\n As well as verifying things work when they are written, tests also act as long-term documentation. They can be run at any point to ensure that they still pass and are a reference to other developers on how the code should work.<\/p>\n\n Rather than a Confluence page, a README file or code comments which can become out of date, if a test becomes outdated, it will fail and make developers aware, as well as break any CI pipeline that it runs in.<\/p>\n\n By writing tests, you're ensuring that your code works as expected and documenting it at the same time.<\/p>\n\n ",
"format": "full_html",
"processed": "\n Today I was working on a project and made a one-line change that updated a single value within an API response.<\/p>\n\n Unexpectedly, it caused a test to fail. The API response returned a 500 status code instead of the expected 201 code.<\/p>\n\n I reverted the change locally and ensured that the test passed again, so I knew it was causing the failure.<\/p>\n\n The change was removing a hard-coded part of a URL to a dynamic one, using Drupal's I was retrieving a value from it, but as there was no value being set within the test, it was returning a null value and causing the 500 error code.<\/p>\n\n To fix the test failure, I needed to learn how to set a Settings value within a test.<\/p>\n\n To do this, I looked for and found the test for the Settings class itself. I saw how it was being set there, did the same in my test, fixed the failure and got my test passing again.<\/p>\n\n As well as verifying things work when they are written, tests also act as long-term documentation. They can be run at any point to ensure that they still pass and are a reference to other developers on how the code should work.<\/p>\n\n Rather than a Confluence page, a README file or code comments which can become out of date, if a test becomes outdated, it will fail and make developers aware, as well as break any CI pipeline that it runs in.<\/p>\n\n By writing tests, you're ensuring that your code works as expected and documenting it at the same time.<\/p>\n\n ",
"summary": null
}
],
"feeds_item": [
{
"imported": "2025-04-16T14:13:05+00:00",
"guid": null,
"hash": "fd83c2fde1dc9ee8eddd826af1ec88b8",
"target_type": "feeds_feed",
"target_uuid": "90c85284-7ca8-4074-9178-97ff8384fe76"
}
]
}Settings<\/code> class.<\/p>\n\n
How does the Settings class work?<\/h2>\n\n
Tests are living documentation<\/h2>\n\n
Fixing the failure<\/h2>\n\n
Settings<\/code> class.<\/p>\n\n
How does the Settings class work?<\/h2>\n\n
Tests are living documentation<\/h2>\n\n