##Explanation TryingI'm trying to get better unit test coverage of my server.
Because I did not want to do this ad-hoc, I addadded some automated tools to my build scripts that do all the work.
In the test directory I have a Mock.def
that defines the system calls I want to mock. It supportsupports two types of line: #include
and MOCK_SYSTEM_FUNC
.
When building the unit tests, the MockHeaders.cpp is compiled and linked with the unit teststests; MockHeaders.h is forced on all the source files with the -include
directive from gcc
.
The ThorMock.h
can be included by and unit tests that want to mock out a system file.
##Building The Code Thatcode that generates the three files is (Its part of the generalized Makefile I have, so all my projects can now use the mocking technique). If anyobodyanybody can help make this neater I would appreciate the input.
So inIn unit test builds (or code coverage builds as I call them) there is an indirection. The system call is actually held in a variable and must be looked up. So there is a slight penalty when running the tests.
This indirection is not compiled into the debug or release versions. So these buildbuilds do not see any indirection.
SometimeSometimes the system names are just too common. And defining a macro to override them will hit more of your function names thenthan you actually want (examples are read()
and write()
). In these cases I have had to define a wrapper function in the header file: