Automatic mock creation for unit tests in C and C++.
ccmock either needs a compilation database or a compile_flags.txt to be able to parse a project's source files.
- Automatic detection which functions need to be mocked.
- Blacklist entries
- Supported frameworks: * gmock * fff
Depending on which compiler you prefer, chose either * gcc 12.1.0 or * clang 14.0.0.
Also depending on what you prefer, chose either * make or * ninja 1.10.
In any case, you'll also need to following programs to build ccmock from source:
Install all required tools and libraries (chosing the most conservative options):
pacman -Syu llvm clang bash gcc git cmake makeapt-get install llvm llvm-dev clang libclang-dev bash gcc g++ git cmake makeConfigure the build system:
cmake -B build -DCMAKE_BUILD_TYPE=releaseBuild the project with clang:
cmake --build buildInstall the built program to /usr/local/bin:
cmake --install build --stripGenerate a compilation database compile_commands.json for your project.
Feed the source file and the compilation database into ccmock to create mocks for your unit test code.
ccmock --compile-commands=compile_commands.json -o <output> <input>Use the preprocessor to include the generated output file in your unit test source file.
Focus on writing unit test code.
ccmockccmock --helpccmock -hccmock <input-file>ccmock -o <output-file> <input-file>ccmock --compile-commands=compile_flags.txt <input-file>ccmock --compile-commands=compile_commands.json <input-file>ccmock --config=<config>.yamlccmock --config=<config>.yaml,<config>.yaml <input-file>CCMOCK_CONFIG=<config>.yaml ccmock --config=<config>.yaml,<config>.yaml <input-file>ccmock --dump-configccmock --dump-config -o <output-file>ccmock --config=<config>.yaml,<config>.yaml --blacklist=<name> --dump-configccmock --extra-args=-DNDEBUG,-Wall,-Werror <input-file>- Always name your parameters in function declarations.
- Don't mock very fundamental functions like malloc(), open(), etc... as doing so will very likey break your unit test library in unpredictable ways.
Explore the test/system directory to see how ccmock can be integrated into a build system for automatic mock generation.
C++ * Mock function calls are not associated to any specific object instance. * The constructors and destructors of global objects cannot be checked with
mock calls.
- Global objects can only be automatically instantiated if they have a default constructor.
- Mocking C++ is not implemented
- Fake Function Framework generator not implemented
- Generate global variable definitions
- Restructure test tree
- Automatic include handling
- Provide multiple test runners (gtest, unity?, ctest?)
- Add support for another mock library (cpputest?)
- Implement own mocking functionality
- --backend None to just print prototypes