eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.22k stars 169 forks source link

Add Any verification specifier #199

Closed oriolarcas closed 3 years ago

oriolarcas commented 4 years ago

A flexible test may want to ignore invocations of trivial methods, like getters and read only functions. Such methods may be called any number of times, including none.

Currently FakeIt has no way to discard the invocations of a sequence of methods. Using ClearInvocationHistory would discard all the methods, trivial or not.

This new verification specifier, Any, marks a method or sequence of methods as verified, regardless of the number of invocations (including none).

Example:

Verify(Method(mock, important_method)).Exactly(3);
Verify(Method(mock, trivial_getter)).Any();
VerifyNoOtherInvocations(mock);

Using this modifier, a flexible test may white-list the trivial methods, and make sure that important methods are not called.

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 0.0% when pulling 4a6e77e07fe98adb558b612f54b61f2b93c42afe on oriolarcas:dev into de1b4795a5cf8073786b469d565814c9a0253fa3 on eranpeer:dev.

Warchant commented 4 years ago

@eranpeer pls land this PR

eranpeer commented 3 years ago

unit tests?

FranckRJ commented 3 years ago

I wanted to rebase your branch on top of master (so, without the commits on dev branch) but I don't exactly know how to do that. So I just cherrypicked the commit and created a new branch #247.