Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fakeit mocking header library for unit tests #171

Merged
merged 5 commits into from
Oct 16, 2018
Merged

add fakeit mocking header library for unit tests #171

merged 5 commits into from
Oct 16, 2018

Conversation

scravy
Copy link
Member

@scravy scravy commented Oct 16, 2018

Extracted from #137

This includes the header-only fakeit library into the unit test target (so no dependencies added to united etc.). fakeit can mock interfaces (anything which std::is_polymorphic yields true for ;-)).

Here are usage examples extracted from their README:

class 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));

@scravy scravy self-assigned this Oct 16, 2018
@scravy scravy added tests Automated tests utils/logs labels Oct 16, 2018
@scravy scravy added this to the Initial polish for maintenance milestone Oct 16, 2018
Copy link
Member

@AM5800 AM5800 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is cool to have a mocking library.
utACK

Copy link
Member

@kostyantyn kostyantyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConceptACK

@Gnappuraz
Copy link
Member

❤️ utACK bfe6917

@Ruteri
Copy link
Member

Ruteri commented Oct 16, 2018

utACK, very cool.
The linter failed and we probably want to exclude the file.

@scravy
Copy link
Member Author

scravy commented Oct 16, 2018

@Ruteri The linter failed on whitespace in the README.

@scravy scravy merged commit 7cf811f into master Oct 16, 2018
@scravy scravy deleted the add-fakeit branch October 16, 2018 11:32
frolosofsky pushed a commit that referenced this pull request Oct 31, 2018
Extracted from #137 

This includes the header-only [fakeit](https://github.com/eranpeer/FakeIt) library into the unit test target (so no dependencies added to `united` etc.). `fakeit` can mock interfaces (anything which `std::is_polymorphic` yields true for ;-)).

Here are usage examples extracted from their README:

```cpp
class SomeInterface {
	virtual int foo(int) = 0;
	virtual int bar(string) = 0;
};
```
```cpp
// 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
```cpp
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));
```
@cornelius cornelius added the tools Development tools label Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Automated tests tools Development tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants