Is it good practice to use the weak attribute in production code so that for test code one can override functions?
Asked
Active
Viewed 112 times
1
-
I suggest you check the Stack Exchange Q&A site on [Software Quality Assurance and Testing](http://sqa.stackexchange.com/), maybe you will find it helpful. – codeaviator Mar 07 '16 at 08:34
1 Answers
3
I don't know if it is good practice, but there are ways to override functions in test code that do not interfere with production code:
- using macros that redefine the function names you wish to override
- using
LD_PRELOAD
- using macros that expand to
__weak
in debug mode and to nothing in production mode.

chqrlie
- 131,814
- 10
- 121
- 189