I am trying to setup Agile and TDD environment for MFC applications that require high performance.
Since MFC View/Document are not testable, I am going to make them as dumb as possible and to test the other classes with Boost Test framework. – Please let me know if you know better way or better test framework for this environment.
In order to make TDD work, I think having dependency injection is crucial for loosely coupled structure. How can I achieve this? Any reference or hint will be appreciated.
Use shared_ptr’s to interfaces representing your classes.
I am thinking something like
Then you could just take the clock implementation in your constructor, or have another method to set the implementation, like setClock or something.
Example of this would be
Then in your unit testing you could do something like this:
You can also just ignore resources. The shared_ptr’s will delete themselves.
The cost to this would be a little performance loss due to dynamic allocation, virtual function calls, and the overhead of shared_ptr.
The benefits would be increased modularity, lowered compile time, easier use of mocking frameworks like googlemock(they require interfaces anyways), and easier resource management(you will never have a null pointer).