We have spent a lot of time on the core concepts of object-oriented design and programming.  However, testing object-oriented code is at least as essential to our practical approach.  We need to ensure that our code is written with a quality that makes it worth re-using.  Otherwise, it is a better use of time to write new code instead of wrangle low-quality code with the idea of re-use.  We have all seen these situations where it is easier and faster to start from scratch than building on previously written code.


Testing Object-Oriented Code Through Design

We will focus on test-driven development in the next episode.  However, our implementation and approach to a solution can be improved with the inclusion of unit tests.  There is a level of expectation that unit tests point to.  When we start to code these, the gaps in our return values and messages become apparent.  Thus, we get the benefits of tested code and a more thorough design.

Unit and Class-Level Testing

Unit-testing typically is at the method level.  The good news is that we can connect a few of these and easily shift to class-level tests.  These are important steps towards building a highly re-usable class.  We will show (through successful tests) that our methods work individually and as part of the class system.  While interactions and interfaces for our class are important, it is more valuable to have a class that is a solid ecosystem.

The Goal Is Re-Usable

All of these points lead us to how confident we are in our code.  If we have a low-confidence, then why would we re-use it?  In those cases, we are better off writing “one-off” code that avoids the costs of object-oriented.  There is no benefit in staying on the fence.  Either embrace OOD and testing object-oriented code for re-use or write something quick-and-dirty.  This concept applies throughout the real world.  There is no sense building on a flimsy foundation.

Rob Broadhead

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

Leave a Reply