Quality Assurance is an art as well as a skill.  We all can randomly break things.  However, testing is not just about breaking things.  It is also done with the goal of providing a sense of quality and stability.  Thus, we need to be intentional with our plans.  This process starts at the smallest level so let’s look at three ways to improve unit testing.

Create and Test For Exceptions, Notifications, and Messages

One piece of the user experience is messaging and notifications.  These may appear to confirm a step, show success, or point to errors.  When we build a unit of code, then we need to include ways to provide feedback for these messages.  This functionality provides a way to improve unit testing.  Unit tests are often built to show the “happy path” and then an invalid path or two.  A better approach is to walk through the code for every possible category of failure and ensure it handles each one correctly.  The notifications and messages are indicators of these failure categories.  You can see them in the requirements.  However, the code provides a perfect level of granularity for us to exercise each logical path.  When we are done writing our tests, there should be a validation of every error or success code and message the unit can produce.

A General Approach To Testing Strategies For Developers

Improve Unit Testing Through Edge Cases

This suggestion is a common one in our past discussions.  Nevertheless, this is an essential piece for us to improve unit testing.  Code tends to break as we get to the edges.  This trend is due, in part, to that being where details become critical. Also, it comes from how many test values are not on the edges.  We tend to test around the happy path more than edges.  It is easier to randomly pick values closest to the happy path in many situations so that should be expected.  The details are a critical part of high-quality code.  Thus, those are what we want to center our tests around.  Provide unit tests that are just inside, just outside, and precisely on the limits of acceptable values.  The majority of bugs live here so match that knowledge to your testing approach. 

Build And Test As You Code

When we test and find a bug, the amount of potentially broken code is critical to a fix.  The faster we narrow down the scope to the lines that cause the bug, the shorter the time to start on a fix.  Thus, it is only logical to reduce our testing to small and well-known units of code.  While unit testing should focus on small chunks of code, those are not always stand-alone n nature.  There are often system-level rules and data that provide assumptions for our functional piece.  When we are unsure of the quality and validity of those other units, then we might see a false fail for our code.  Therefore, we are going to be able to tests and fix better if we are building on pieces that are known to be correct.  We will see this when we test as we develop.  This approach also helps to create a good habit of writing unit tests for all of our code.  In the end, we should not consider a unit as “done” until there are unit tests for that code as well as the source itself.

Simple Guide to Testing: Don’t Forget To Test Your Code.

Rob Broadhead

Rob is a founder of, and frequent contributor to, Develpreneur. This includes the Building Better Developers podcast. He is also a lifetime learner as a developer, designer, and manager of software solutions. Rob is the founder of RB Consulting and has managed to author a book about his family experiences and a few about becoming a better developer. In his free time, he stays busy raising five children (although they have grown into adults). When he has a chance to breathe, he is on the ice playing hockey to relax or working on his ballroom dance skills.

Leave a Reply