Member-only story
What is the Business Value of Unit Testing? Part 1
We’ve been doing a lot more concentration on unit testing at work lately, and a question has come up. What value do automated unit tests provide?
The text book(ish) answer is:
if you’re unit testing your code with relevant asserts, with good enough code coverage, the less likely there will be bugs. Sounds great! Why isn’t everyone doing it? Unit testing does require a certain style of coding, loose dependencies, and a certain amount of planning. Here’s a good SO answer that goes into some detail on how/why unit testing is great — but I like examples.
Requirements change. It’s a fact of (programming) life. Something that held true today, might not be true months or years down the road. One of the great things about unit tests and code coverage is that when considered together, you can really get a feel for if your code is working correctly, even create requirements based on your unit tests! On to the example — we’re going to build a super important piece of business logic based on this requirement: > As a user, I need a way to enter a number. Once the number has been entered, I need it to be printed back to me.
Well that sounds easy. Going to start a new github repo to track progress.
So based on our requirement. I’m going to create a console application that takes a user’s entry, and then prints it back to them.. This is probably the most useful business logic in the history of the universe. Based on the requirement, I’ve…