
[Please do not mail me a copy of your followup] boost-users@lists.boost.org spake the secret code <20100609080130.21006u389wm3wotm@webmail.hiwaay.net> thusly:
I am testing class A. However, class A makes some calls to class B. Does Boost.Test provide any "test harness" capability so that the responses from class B can be canned. I really only want to test class A, not A and B together. I hope the question makes sense.
You need to decouple the classes somehow. The easiest way is to use an interface to separate them, in C++ terms a pure virtual base class for B. In my 5-part tutorial on using Boost.Test, you can see the use of an interface to decouple a class from its collaborator in part 4. http://legalizeadulthood.wordpress.com/2009/07/05/c-unit-tests-with-boost-te... There are lots of ways to decouple two collaborators, but I like "Extract Interface" the best. If for some reason your code is too performance sensitive for an interface sitting in the middle, you can decouple the collaborators with templates. I give an example of how to decouple your code from the Win32 API using templates here: http://legalizeadulthood.wordpress.com/2007/12/17/faking-out-the-win32-api-w... The book "Working Effectively With Legacy Code" provides lots of good ideas on how to decouple your system under test from its dependencies. I wrote a review of it here: http://legalizeadulthood.wordpress.com/2007/04/11/working-effectively-with-l... -- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/ Legalize Adulthood! http://legalizeadulthood.wordpress.com