|home |print view |recent changes |changed October 14, 2011 | |You are 126.96.36.199 <- set your identity!
Mockator Pro – A C++ Mock Object Library With Eclipse Support
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.
C++, mock object, Eclipse, static polymorphism, dependency injection
Michael Rüegg is a scientific assistant at IFS Institute for Software and holds a diploma in computer science of FHO/HSR Rapperswil. He works on refactoring Eclipse plug-ins for C++. Mockator Pro is his master thesis project.
Prof. Peter Sommerlad is head of IFS Institute for Software at FHO/HSR Rapperswil. Peter is co-author of the books POSA Vol.1 and Security Patterns. His goal is to make software simpler by Decremental Development: Refactoring software down to 10% its size with better architecture, testability and quality and functionality. The original idea behind Mockator Pro was inspired by him.
Mockator Pro will be available free of charge when Michael Rüegg's master thesis is done. Preliminary versions will be downloadable before the ACCU conference.
|Last edited October 14, 2011||