Test-After Development Sins (Ignoring cross-cutting concerns)

February 18, 2012 | Legacy Code

series of articles exploring the impact of writing tests after the code is written on the implementation part of SDLC.

Sin No.3: Ignoring cross-cutting concerns.

The problem with this approach becomes very clear. It will be hard and tedious work, inside each test, to create stubs and mocks for each and every aspect. The intent of the unit tests will also look wrong since, in reality, these aspects should not be treated as dependencies of the SUT.

Among others, logging and caching are cross-cutting concerns that can easily slip through the services (making us treat them as normal dependencies). 

While the preferred way to model these aspects is using decorators and/or dynamic interceptors, there are many times that we see classes violating the SRP containing all-in-one logging, caching, auditing and other aspects (and even violating the ISP with a coarse-grained Header Interface).