{"id":13418537,"url":"https://github.com/eranpeer/FakeIt","last_synced_at":"2025-03-15T03:31:28.736Z","repository":{"id":37270151,"uuid":"12526458","full_name":"eranpeer/FakeIt","owner":"eranpeer","description":"C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.","archived":false,"fork":false,"pushed_at":"2024-10-06T18:57:55.000Z","size":15991,"stargazers_count":1248,"open_issues_count":73,"forks_count":174,"subscribers_count":41,"default_branch":"master","last_synced_at":"2024-10-29T15:34:40.110Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eranpeer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-01T20:36:44.000Z","updated_at":"2024-10-29T01:06:44.000Z","dependencies_parsed_at":"2024-04-14T16:34:06.881Z","dependency_job_id":"73c273a2-9869-4246-9f5c-e567f1ef4641","html_url":"https://github.com/eranpeer/FakeIt","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eranpeer%2FFakeIt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eranpeer%2FFakeIt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eranpeer%2FFakeIt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eranpeer%2FFakeIt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eranpeer","download_url":"https://codeload.github.com/eranpeer/FakeIt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243664024,"owners_count":20327405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:03.477Z","updated_at":"2025-03-15T03:31:28.730Z","avatar_url":"https://github.com/eranpeer.png","language":"C++","readme":"FakeIt\n======\n \n[![Join the chat at https://gitter.im/eranpeer/FakeIt](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/eranpeer/FakeIt?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nLinux / GCC: [![CI Linux/GCC](https://github.com/eranpeer/FakeIt/actions/workflows/ci_linux_gcc.yml/badge.svg?branch=master\u0026event=push)](https://github.com/eranpeer/FakeIt/actions/workflows/ci_linux_gcc.yml?query=branch%3Amaster+event%3Apush)\n[![Coverage Status](https://coveralls.io/repos/github/eranpeer/FakeIt/badge.svg?branch=master)](https://coveralls.io/github/eranpeer/FakeIt?branch=master)\n\nLinux / Clang: [![CI Linux/Clang](https://github.com/eranpeer/FakeIt/actions/workflows/ci_linux_clang.yml/badge.svg?branch=master\u0026event=push)](https://github.com/eranpeer/FakeIt/actions/workflows/ci_linux_clang.yml?query=branch%3Amaster+event%3Apush)\n\nMSVC: [![CI Windows/MSVC](https://github.com/eranpeer/FakeIt/actions/workflows/ci_windows_msvc.yml/badge.svg?branch=master\u0026event=push)](https://github.com/eranpeer/FakeIt/actions/workflows/ci_windows_msvc.yml?query=branch%3Amaster+event%3Apush)\n\nFakeIt is a simple mocking framework for C++. It supports GCC, Clang and MS Visual C++.\n\nFakeIt is written in C++11 and can be used for testing both C++11 and C++ projects.\n\n```cpp\nstruct SomeInterface {\n    virtual int foo(int) = 0;\n    virtual int bar(string) = 0;\n};\n```\n\n```cpp\n// Instantiate a mock object.\nMock\u003cSomeInterface\u003e mock;\n\n// Setup mock behavior.\nWhen(Method(mock,foo)).Return(1); // Method mock.foo will return 1 once.\n\n// Fetch the mock instance.\nSomeInterface \u0026i = mock.get();\n\n// Will print \"1\". \ncout \u003c\u003c i.foo(0);\n```\n\nVerify method invocation:\n\n```cpp\nMock\u003cSomeInterface\u003e mock;\n\t\t\nWhen(Method(mock,foo)).Return(0);\n\nSomeInterface \u0026i = mock.get();\n\n// Production code\ni.foo(1);\n\n// Verify method mock.foo was invoked.\nVerify(Method(mock,foo));\n\n// Verify method mock.foo was invoked with specific arguments.\nVerify(Method(mock,foo).Using(1));\n```\n\nCheckout the [Quickstart](https://github.com/eranpeer/FakeIt/wiki/Quickstart) for many more examples!\n\nThe master branch has the stable version of FakeIt. Include the most suitable single header in your test project and you are good to go.\n\n## Features\n* Packaged as a **single header file**.\n* Very simple API based on the expressiveness of C++11.\n* Supports all major compilers: GCC, Clang and MSC++.\n* Easily integrated with [**GTest**](https://code.google.com/p/googletest/), [**MS Test**](http://en.wikipedia.org/wiki/Visual_Studio_Unit_Testing_Framework) and [**Boost Test**](http://www.boost.org/doc/libs/1_56_0/libs/test/doc/html/index.html).\n* Expressive [Arrange-Act-Assert](http://xp123.com/articles/3a-arrange-act-assert/) syntax.\n* Create mock classes or **spy existing objects** instantly in one simple line.\n* No limitation on number of method arguments.\n* Supports dynamic casting.\n\n## Installation\nFakeIt is a header only framework. It does not require any installation. For extra simplicity fakeit is packaged as a single header file.\n\nFakeIt is pre-configured to work with some of the major unit testing frameworks. A pre-configured version will use the assertions mechanism of the unit testing framework to integrate the generated error messages into the unit testing framework output.\n\nIf you don't find your unit testing framework on the list, simply use the *standalone* configuration.\n\n\n### Configurations' name\n\nHere's the list of each unit testing framework FakeIt is pre-configured with and the name of the respective configuration to use if you want FakeIt to integrate with them (if your favorite unit testing framework is not on the list, simply use the `standalone` configuration):\n* GoogleTest: `gtest`\n* MSTest: `mstest`\n* Boost.Test: `boost`\n* Catch2: `catch`\n* tpunit++: `tpunit`\n* mettle: `mettle`\n* Qt Test: `qtest`\n* NUnit: `nunit`\n* CUTE: `cute`\n* doctest: `doctest`\n* Without a unit test framework: `standalone`\n\n### Using a pre-packaged single header file\nPre-packaged single header versions of FakeIt are located under the *single_header* folder.\nDepending on the unit testing framework you use, simply add one of the pre-packaged versions to the include path of your test project:\n\n* \u003cfakeit_folder\u003e/single\\_header/[gtest](https://github.com/google/googletest)\n* \u003cfakeit_folder\u003e/single\\_header/mstest\n* \u003cfakeit_folder\u003e/single\\_header/boost\n* \u003cfakeit_folder\u003e/single\\_header/[catch](https://github.com/catchorg/Catch2) - (v2 and v3)\n* \u003cfakeit_folder\u003e/single\\_header/[tpunit](https://github.com/tpounds/tpunitpp)\n* \u003cfakeit_folder\u003e/single\\_header/[mettle](https://github.com/jimporter/mettle)\n* \u003cfakeit_folder\u003e/single\\_header/qtest\n* \u003cfakeit_folder\u003e/single\\_header/nunit - (See caveats in config/nunit/fakeit\\_instance.hpp)\n* \u003cfakeit_folder\u003e/single\\_header/[cute](https://github.com/PeterSommerlad/CUTE)\n* \u003cfakeit_folder\u003e/single\\_header/[doctest](https://github.com/doctest/doctest)\n* \u003cfakeit_folder\u003e/single\\_header/standalone - (if you don't use a unit testing framework)\n\nFor example, to use fakeit with **Google Test** simply add the *single_header/gtest* folder to the include path of your test project:\n```\n-I\"\u003cfakeit_folder\u003e/single_header/gtest\"\n```\n\n### Using the source header files\nFakeit source code header files are located under the *include* foler. To use FakeIt directly from the source code all you need to do is to download the source files and add the *include* folder and the configuration folder of your choice to the include path of your project.\nFor example:\n\n* To use fakeit with **Google Test** add the *include* folder and the *config/gtest* folder to the include path of your test project:\n```\n-I\"\u003cfakeit_folder\u003e/include\" -I\"\u003cfakeit_folder\u003e/config/gtest\"\n```\n* For every other unit test framework (or for using FakeIt without a unit test framework), just replace `gtest` by the name of the configuration (see `Configurations' name` section for details).\n* If you use FakeIt with **NUnit** in a managed Visual Studio C++/CLI project, note that it is useful to define your mocks in `#pragma unmanaged` sections so that you can use lambda expressions.\n\nIt is recommended to build and run the unit tests to make sure FakeIt fits your environment.\n\nFor GCC, it is recommended to build the test project with -O1 or -O0 flags. Some features of FakeIt may not work with stronger optimizations!!\n\n### Installing FakeIt with CMake\n\nClone the repository, `cd` into it then execute the following commands:\n```\ncmake -S . -B build -DCMAKE_INSTALL_PREFIX=\u003cINSTALL_DIR\u003e\ncmake --build build\ncmake --install build\n```\n\nReplace `\u003cINSTALL_DIR\u003e` by the path of the directory where you want to install FakeIt.\n\nThen in your project's `CMakeLists.txt`:\n```\nfind_package(FakeIt REQUIRED)\n[...]\ntarget_link_libraries(\u003cYOUR_TARGET\u003e PRIVATE FakeIt::FakeIt-\u003cCONFIG\u003e)\n```\n\nWhere `\u003cYOUR_TARGET\u003e` is the name of the target you want to link FakeIt with, and `\u003cCONFIG\u003e` is the name of the specific configuration you want to use (see `Configurations' name` section for details).\n\nThen, when you'll invoke CMake's configure command, pass the argument `-DFakeIt_ROOT=\u003cINSTALL_DIR\u003e`, with `\u003cINSTALL_DIR\u003e` being the directory where you installed FakeIt.\n\n### Installing FakeIt through Conan\n\nTo use FakeIt with Conan, you'll need a `conanfile.txt` like this: \n```\n[requires]\nfakeit/\u003cVERSION\u003e\n\n[options]\nfakeit:integration=\u003cCONFIG\u003e\n```\n\nReplace `\u003cVERSION\u003e` by the version of FakeIt you want to use, and `\u003cCONFIG\u003e` with the name of the configuration you want to use (see `Configurations' name` section for details).\n\n### Installing FakeIt through vcpkg\n\nYou can download and install fakeit using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:\n\n    git clone https://github.com/Microsoft/vcpkg.git\n    cd vcpkg\n    ./bootstrap-vcpkg.sh\n    ./vcpkg integrate install\n    ./vcpkg install fakeit\n\nThe fakeit port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.\n\n## Running the tests\n\n### Building and Running the Unit Tests with GCC\n```\nCC=gcc CXX=g++ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTING=ON\ncmake --build build -j\n```\nRun the tests by typing:\n```\n./build/tests/FakeIt_tests\n```\n\n### Building and Running the Unit Tests with Clang\n```\nCC=clang CXX=clang++ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTING=ON\ncmake --build build -j\n```\nRun the tests by typing:\n```\n./build/tests/FakeIt_tests\n```\n\n### Building and Running the Unit Tests with Visual Studio \n```\ncmake -S . -B build -G \"Visual Studio 17 2022\" -DENABLE_TESTING=ON\ncmake --build build --config Debug -j\n```\nRun the tests by typing:\n```\n./build/tests/Debug/FakeIt_tests.exe\n```\n\n## Limitations\n* Currently only GCC, Clang and MSC++ are supported.\n* On GCC, optimization flag O2 and O3 are not supported. You must compile the test project with -O1 or -O0.\n* In MSC++, your project must have Edit And Continue debug mode on (https://msdn.microsoft.com/en-us/library/esaeyddf.aspx) which is same of /ZI compiler switch. If you don't use this, you will have exceptions mocking destructors (which includes unique_ptr and other smart pointers). \n* Can't mock classes with multiple inheritance.\n* Can't mock classes with virtual inheritance.\n* Currently mocks are not thread safe. \n","funding_links":[],"categories":["C++","TODO scan for Android support in followings","Debug","Testing Frameworks","Mocking","Libraries"],"sub_categories":["Testing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feranpeer%2FFakeIt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feranpeer%2FFakeIt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feranpeer%2FFakeIt/lists"}