forked from arstrube/FakeFunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
34 lines (28 loc) · 1.67 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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