I am starting to think about re-architecting a large C++ application with unit testing in mind. Most of the reading that I have done has lead me to mock frameworks (i.e. google mock). However, one of my design goals is to keep the software as simple as possible for easy maintainability.
My issue is that it seems like you need to add considerable complexity to the application in order to build in the dependency injection that is required to use mock classes.
For example, you would need to add abstract base classes for all classes that could need to be mocked so that you can instantiate "production" objects in the production code and "mock" objects in the unit test code. This is somewhat undesirable because of the number of extra classes and the added level of abstraction to all classes. Also, do you add an abstract base class defining the public interface to EVERY class? If you don't, how could you be sure that the class will never need to be mocked?
Or, you need to templatize all of your classes so you can "inject" mock objects in the unit testing code. I definitely do not want an application where every class is a template class.
What has everyone's experience been with this? How have you built testability into your architecture and what has the outcome been?
Aucun commentaire:
Enregistrer un commentaire