Purpose of using mock objects

When testing C++ source code, it is sometimes difficult to test because it costs much to create the actual object or the test depends on the object a lot. In such cases, using a mock object that mimics the real object can effectively reduce dependencies on the object. Additionally, you can generate specifications, such as the expected number of calls of the mock to verify that the object is being used as intended.

Available toolchians

  • GCC 6.0 or later
  • Visual Studio 2015 and later

The main features of a mock object

  • Setting return parameters and return values of a mock object
  • Setting call count for mock object
  • Checking whether the calls occured in a specific order
  • Adding constraints to parameters
  • etc

Mock object usage

This article explains how to use mock objects in C++ tests.

Need more help with this?
Don’t hesitate to contact us here.

Thanks for your feedback.