fakeit

[brief]

FakeIt is a simple mocking framework for C++.

Join the chat at https://gitter.im/eranpeer/FakeIt

Linux / GCC: Build status Linux/GCC Coverage Status

Linux / Clang: Build status Linux/Clang

MSC: Build status MSC

FakeIt is a simple mocking framework for C++. It supports GCC, Clang and MS Visual C++.

FakeIt is written in C++11 and can be used for testing both C++11 and C++ projects.

struct SomeInterface {
	virtual int foo(int) = 0;
	virtual int bar(string) = 0;
};
// Instantiate a mock object.
Mock<SomeInterface> mock;

// Setup mock behavior.
When(Method(mock,foo)).Return(1); // Method mock.foo will return 1 once.

// Fetch the mock instance.
SomeInterface &i = mock.get();

// Will print "1". 
cout << i.foo(0);


Verify method invocation

Mock<SomeInterface> mock;
		
When(Method(mock,foo)).Return(0);

SomeInterface &i = mock.get();

// Production code
i.foo(1);

// Verify method mock.foo was invoked.
Verify(Method(mock,foo));

// Verify method mock.foo was invoked with specific arguments.
Verify(Method(mock,foo).Using(1));

Checkout the Quickstart for many more examples!

The master branch has the stable version of FakeIt. Include the most suitable single header in your test project and you are good to go.

Features

Installation

FakeIt is a header only framework. It does not require any installation. For extra simplicity fakeit is packaged as a single header file.

FakeIt 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.

If you don't find your unit testing framework on the list, simply use the standalone configuration.

Using a pre-packaged single header file

Pre-packaged single header versions of FakeIt are located under the single_header folder. Depending on the unit testing framework you use, simply add one of the pre-packaged versions to the include path of your test project:

For example, to use fakeit with Google Test simply add the single_header/gtest folder to the include path of your test project:

-I"<fakeit_folder>/single_header/gtest"

Using the source header files

Fakeit 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. For example:

-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/gtest"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/mstest"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/boost"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/catch"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/tpunit"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/mettle"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/qtest"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/cute"
-I"<fakeit_folder>/include" -I"<fakeit_folder>/config/standalone"

It is recommended to build and run the unit tests to make sure FakeIt fits your environment.

For GCC, it is recommended to build the test project with -O1 or -O0 flags. Some features of Fakeit may not work with stonger optimizations!!

Building and Running the Unit Tests with GCC

cd build
make all

run the tests by typing

./fakeit_tests.exe

Building and Running the Unit Tests with Clang

cd build
make -f clang_makefile all

run the tests by typing

./fakeit_tests.exe

Building and Running the Unit Tests with Visual Studio

Open the tests/all_tests.vcxproj project file with Visual Studio. Build and run the project and check the test results.

Limitations

license MIT
project fakeit
url github.com/eranpeer/FakeIt
topics C++mockingfaking
2 Versions
version 2.3.2
repository https://pkg.cppget.org/1/stable
depends 0
requires 1; c++11
reviews +1
version 2.3.0
repository https://pkg.cppget.org/1/stable
depends 0
requires 1; c++11
reviews +1