Take it Easy, Love is Hard

TIELove is a place to look back on. It is an online journal to track what I've learned in web development and to share that with you.

David Vanderhaar

Coding is Easy, Testing is Hard

Why Testing?

It’s the first question I ask when faced with the sub-skill of unit testing. When asking other devs their opinion of testing as a skill, the less experienced skeptically see it as a time-suck. The more experienced devs are simply, too blunt saying, “it’s important” without much explanation as to why. So, why is this the case?

For new developers it’s an easy skill to sweep under the rug and we’ll look at some common barriers in the next section. For experienced developers, even those that have good testing habits, it can be difficult to describe the benefits of testing as they are often experiential in nature. It’s tough to track down the ratio of bugs to lines of code over time unless you were thinking way ahead in your career. To understand the benefits we’ll take a birds-eye view of the why for testing.

Writing tests saves you time in the long run.
Writing tests saves time in countless ways. According to Eric Elliot well-written unit tests serve as free documentation to future dev on a project. This is because each test is given a clear description of its purpose and expected outcome. Tests can also be implemented into a continuous delivery system that blocks bugged code from production, saving you time on backtracking a defective code push.

Unit tests will cut down on QA
This is because manual QA involves a lot of clicking around, loading assets, timing situations so that you can manually test what a user may (or may not) encounter while using your app. I find myself doing this type of thing every day and while it does have a place in the pipeline of creating production-ready web apps, it often sucks disproportionate amounts of time out of a dev’s work day.

Testing increases code quality
This is because writing a test for some function, method or feauture in your API requires deep understanding of the logic and flow of that code. This forces the developer to rescan code blocks for opportunities to improve its logic and/or readability. On top of that if you find that some methods are simply to hefty to easily test, it may signal that this method should be further modularized or just simpler.

Testing decreases bug encounters
Bugs are no match for a proper suite of tests. The Microsoft developer docs describe the test suite as a “regression safety net”, explaing that if a bug is found, a test which reveals the bug is to be written first, then the code is modified until it passes that test while still passing all previous tests. This ensures that the bug will never reappear.

So why aren’t we all writing tests already?

But Why Testing?

Common Barriers to Testing

Perhaps the easiest excuse for me to muster in the fight against writing tests is that it just takes too much time. If you’re in the same boat, you’re not necessarily wrong. Most experienced testers will freely admit that if writing tests isn’t a regular practice for you it is difficult to start –that it does take more time than it saves. But isn’t this the case with most skills? Testing is like riding a bike. The time it takes to learn is greater than the time it takes to walk to where you originally wanted to go, but once you’ve learned you can get to that place and others faster, forever. Bite the bullet, learn testing, save yourself time in the long run. Your return on investment increases exponentially.

Another common barrier is that writing tests seem redundant. This excuse is most likely born out of a misunderstanding for what a test is doing for you. You don’t write tests to squash bugs, you write them to avoid bugs. According to test driven development principles you should write the test first, then write the code that will actually be tested. So, if the tests are written well, the time you end up saving is time you’ll never know you gained. This is why many devs, when first asked, can’t explain the immediate benefits of testing. It’s an experience.

Learn More About it

Here a few great articles on the subject.

  1. 5 Questions Every Unit Test Must Answer
  2. Guideline For Test Driven Development
  3. 9 Benefits of Test Driven Development

Bottom line is that coding is one aspect of what you do but testing will become an equally important partner in your journey to dev greatness. IT will force quality and understanding on all that you code.

Until Next Time

Take it Easy