To demonstrate the various elements of
mockpp a rather simple testing problem will be solved in different ways. There is a class
Consumer which loads a configuration file. This file is a simple text file with a data record in each line. Each line will be processed and written back in a modified form at the end. For simplicity the string "/processed" is appended to the original record. While processing the data a method
calculate is invoked with not exactly defined values.
This is a rather common testing problem: there are two or more classes that depend on each other. When you want to test
Consumer from this example you should pass it an object with predictible behavour, a so-called mock object. Creating an input file in this case and checking the output manually after every change in the sources would become too boring.
A mock object is totally different from the object used in production code and only used for testing. Ideally it is derived from the same base class as the production code.
The following sections will introduce into the most important elements of
mockpp by developing different solutions.
All files are present as working source code to start playing with them under