Home > Point2 - Technical > Test and production code maintainability are equally important

Test and production code maintainability are equally important

March 12, 2009

Yesterday, I attended the sessions of “XUnit Test Patterns and Smells; Improving Test Code and Testability Through Refactoring” by Gerard Meszaros and “Design Patterns Explained from Theory to Practice by Scott L Bain”. Gerard went through a few test smells and patterns, it’s nice to be able to identify the test patterns we have been using in Point2 and associate it with a proper test pattern name like Expected Object, Humble Object.

So far Scott’s session is one of my favorite sessions. His great explanation on the different designs of the Command and Lunar modules of the spacecrafts in Apollo program is so very interesting! 😛 Ok, the spacecraft designs is interesting, but more importantly he provided an innovative way of looking at the Design Patterns in practice. He recapped the guidelines from “Design Pattern: Elements of Reusable Object-Oriented Software” (the book that Scott said “Lots bought, little read, few understood”) by the Gang of Four:

  • Design to interfaces
  • Favor object aggregation over class inheritance
  • Encapsulate the concept that varies

Each design pattern is an example of a design that follows those general advices in the given context. Using the different designs of the spacecraft, Scott illustrated the importance of domain analysis to identify the “forces” (the contextual constraints) and achieving the goal of design by context. He showed how the designs should evolve and emerge as the forces/requirements grow over time by following these guidelines. Good design should have strong cohesion, proper coupling, no redundancy and encapsulation. He pointed out that a developer who knows about design patterns doesn’t mean he/she is pattern-oriented. He mentioned the design pattern repository on the Net Objectives website that is maintained by the community. For each of the design pattern in the repository, there is also a section about testing issue and cost-benifit regarding each pattern.

Scott emphasizes the importance of TDD to enforce the “design of interface by nature” and the importance of production code maintainability, while Gerard emphasizes the importance of the test code maintainability. In a nutshell, we should have a maintainable, good quality code in all aspects of the code base. “Refactoring”, “good patterns” and “clean code” should apply to both test and production code. Just like what Uncle Bob said in his “Clean Code III:Function” session today: “Rules for unit tests are no different than production code”.

By: Nyik San Ting

Advertisements
%d bloggers like this: