Back to proposals-2013
Title: Getting Legacy C/C++ under Test
Proposer: peter_sommerlad
Proposer: michael_rueegg
Type: Presentation
Duration: 90 minutes
Description: Getting Legacy C/C++ under Test: “Introduce Seams” Refactorings and Mockator Mock Object Support Library
C++ has a rich set of libraries which support the creation of fake and mock objects (i. e., test doubles). The overwhelming part of them are based on subtype polymorphism by inheriting the test doubles from a common base class to be able to inject them as well as the real objects into the system under test (SUT). This has the known disadvantages of decreased run-time performance and the software engineering issues that come along with inheritance like tight coupling and fragility. Beside this, these libraries often lack an integration into an IDE.
We at the Institute for Software, are eager to improve this situation and address this with Mockator Pro, a new mock object library and a supporting Eclipse C++ Development Tooling (CDT) plug-in that assists the user in creating test doubles. Mockator Pro both supports C++03 and the new standard C++11.
Beside the mentioned subtype polymorphism - which is supported by a new „extract base class“ refactoring - Mockator Pro offers static polymorphism to inject the test double into the SUT via template parameters. The test doubles are realized as local classes, therefore located in the same function as the unit test code, leading to an increased locality that makes it easier to keep them in sync. A third form of mocking is the use of link seams which allow us to replace existing functions with our own test double functions without touching the SUT.
This talk shows how useful Mockator Pro can be for getting rid of fixed dependencies in your code base by extracting template parameters and base classes. You will see that Mockator Pro is able to generate code for test doubles that allows you to track if your SUT is properly using them. Our static code analysis checkers recognize missing member functions, constructors and operators in the injected test doubles and provide default implementations for them through Eclipse quick fixes.
Beside a practical session with many code examples we will also give an introduction into testing with mock objects in general and compare Mockator Pro to other well-known mock object libraries. Additionally, we will talk about the use of C++11 and its new features in our mock object library that allowed us to greatly reduce the need for preprocessor macros, therefore providing transparency and the chance to debug when problems arise.
Keywords: C++, mock object, Eclipse, static polymorphism, dependency injection
Roger: Yes from me
Asti: yes - Peter is always a great speaker