Skip to content

Latest commit

 

History

History
82 lines (62 loc) · 2.5 KB

README.md

File metadata and controls

82 lines (62 loc) · 2.5 KB

FakeIt

GCC: Build Status GCC Coverage Status

MSC: Build status MSC

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

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!

Download the Latest Release and start using FakeIt now!

Features

  • Very simple API based on the expressiveness of C++11.
  • Supports both GCC and MS C++.
  • Expressive Arrange-Act-Assert syntax.
  • Create mock classes or spy existing objects instantly in one simple line.
  • No limitation on number of method arguments.
  • Supports dynamic casting.

Installation

FakeIt is a template library. It does not require any installation. All you need to do is to download the source files and add the "include" folder to the include path of your project. It is recommended to build and run the unit tests to make sure FakeIt fits your environment.

Building and Running the Unit Tests with GCC

cd build
make all

run the tests by typing

./fakit_tests.exe

Building and Running the Unit Tests with Visual Studio

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

Limitations

  • Currently only GCC and MS C++ are supported.
  • Can't mock classes with multiple inheritance.
  • Can't mock classes with virtual inheritance.
  • Currently mocks are not thread safe.