"value":"\n <p>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<p>Unexpectedly, it caused a test to fail. The API response returned a 500 status code instead of the expected 201 code.<\/p>\n\n<p>I reverted the change locally and ensured that the test passed again, so I knew it was causing the failure.<\/p>\n\n<h2 id=\"fixing-the-failure\">Fixing the failure<\/h2>\n\n<p>The change was removing a hard-coded part of a URL to a dynamic one, using Drupal's <code>Settings<\/code> class.<\/p>\n\n<p>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<h2 id=\"how-does-the-settings-class-work%3F\">How does the Settings class work?<\/h2>\n\n<p>To fix the test failure, I needed to learn how to set a Settings value within a test.<\/p>\n\n<p>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<h2 id=\"tests-are-living-documentation\">Tests are living documentation<\/h2>\n\n<p>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<p>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<p>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 <p>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<p>Unexpectedly, it caused a test to fail. The API response returned a 500 status code instead of the expected 201 code.<\/p>\n\n<p>I reverted the change locally and ensured that the test passed again, so I knew it was causing the failure.<\/p>\n\n<h2 id=\"fixing-the-failure\">Fixing the failure<\/h2>\n\n<p>The change was removing a hard-coded part of a URL to a dynamic one, using Drupal's <code>Settings<\/code> class.<\/p>\n\n<p>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<h2 id=\"how-does-the-settings-class-work%3F\">How does the Settings class work?<\/h2>\n\n<p>To fix the test failure, I needed to learn how to set a Settings value within a test.<\/p>\n\n<p>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<h2 id=\"tests-are-living-documentation\">Tests are living documentation<\/h2>\n\n<p>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<p>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<p>By writing tests, you're ensuring that your code works as expected and documenting it at the same time.<\/p>\n\n ",