Jump to content

01d55

Community Newbie
  • Posts

    1
  • Joined

  • Last visited

01d55's Achievements

Tiro

Tiro (1/14)

0

Reputation

  1. C & C++ code can be much less tightly coupled than it appearances suggest, thanks to the compilation model. Any source file that can be compiled to an object file is necessarily isolatable as a testable unit. For example, suppose class B depends on class A, and appears to be tightly coupled (e.g. B composites A by value, or A's methods aren't virtual). However, A and B have been written in the normal way: A.hxx declares class A, A.cxx defines class A's methods, and likewise for B.hxx and B.cxx. It is therefore possible to write a file, A_mock.cxx, which also defines class A's methods, and link A_mock.o instead of A.o in the test executable. This method of unit testing by compilation unit uses seperate executables for each unit tested. Every symbol referenced but not defined in the compilation unit under test is defined by the test code and any such symbol the test writer overlooks stops the test from being linked. This doesn't save you from tight linkages when functions are defined in a header, but moving definitions out of headers is much less risky than re-architecting code so that it is isolatable through polymorphism.
×
×
  • Create New...