forked from arstrube/FakeFunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
mhuangwm/FakeFunctions
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
RUNTIME-SELECTABLE CPPUTEST FAKE FUNCTION EXAMPLE Sometimes, when faking a module, it is desirable to use production code for some functions, while mocking others, and using dummies for elsewhere, all in the same test executable. This cannot be done via linker substitution. This code is a very basic example of how to set up fake functions that can be swapped individually at run-time. The assumption is that the code to be tested is written in pure C. Our fake functions, on the other hand, work by harnessing the full power of object-oriented design and the C++ language. I have tried to keep everything as simple as possible. Used.c - C Module that other code depends on User.c - C Module that depends on the above Used_Fakes.cpp - This is really C code - it only uses the convenience of leaving out unused parameter names. It lets you choose at run-time via the UT_PTR_SET macro, whether each individual function should be mocked, stubbed, replaced by a dummy, or whether the real implementation will be called for the Used module. Default is to use empty dummies. RunAllTests.cpp - Unit tests that test-drive all of the above and demonstrate how to use it. RunAllTests2.cpp - Presents the whole thing in one file for easier understanding. This does not include real code for Used_xxx(). This is just a very basic example; no guarantees for usefulness or anything! Use as a template for building your own fake functions. (c) 2014 Arnd R. Strube
About
An example run-time substitutable generic fake functions for use with CppUTest.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- C++ 89.1%
- C 10.9%