{"componentChunkName":"component---src-templates-blog-post-js","path":"/write-tests-now/","result":{"data":{"site":{"siteMetadata":{"title":"Little and Often"}},"markdownRemark":{"id":"92b4cb2a-982d-5b81-98f9-f5fd1011c380","excerpt":"“I can’t add tests to this app. It’s not got a test suite yet. The code isn’t written in units. I can’t mock out the database”. These are several concerns I…","html":"<p>“I can’t add tests to this app. It’s not got a test suite yet. The code isn’t written in units. I can’t mock out the database”.</p>\n<p>These are several concerns I voiced in my head looking at a legacy PHP application. It was a minefield of functions and <code class=\"language-text\">include</code> statements. A variable would thread through several files. “I can’t possibly write tests for this” I told my self.</p>\n<p>I was wrong. And so are you.</p>\n<h2>Where to start?</h2>\n<p>In my case, I started with bugs. When a bug was reported I took the time to add a test then fix the bug. This has a few great benefits</p>\n<ol>\n<li>You’re forced to add some rudimentary testing harnesses</li>\n<li>You prove the bug actually exists</li>\n<li>The bug has already been understood before commencing work</li>\n<li>The bug is documented via a test. Future developers are thus forced to keep it fixed.</li>\n<li>You’ve added the first test to the application!</li>\n</ol>\n<p>The guiding principle in any software project is the <a href=\"https://97-things-every-x-should-know.gitbooks.io/97-things-every-programmer-should-know/content/en/thing_08/\" title=\"Boy Scouts Rule\">Boy Scouts rule</a>. In short this rule dictates that the code should always be checked in <em>a little</em> bit better than it was checked out. Not perfection. Just a little better.</p>\n<p>The key as with many things is to just get started. Having a test will move the codebase in a good direction.</p>","frontmatter":{"title":"Write. Tests. Now.","date":"January 20, 2020","description":"Tests won't write themselves. Write them now or forever regret it."}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"slug":"/write-tests-now/","previous":{"fields":{"slug":"/free-hosting-with-netlify/"},"frontmatter":{"title":"Hosting a website (for free!) with Netlify"}},"next":null}}}