Comments (2)
Thank you for trying FakeIt.
Currently, FakeIt doesn't support spying an object or partially mocking a
class.
I'm looking for a technical solution that will enable spying in both GCC
and MSC++.
Hopefully, I'll be able to support spying soon.
Regards,
Eran.
On Tue, Jun 3, 2014 at 6:39 AM, jpeterman1 [email protected] wrote:
Sometimes it can be convenient to use the methods of the real underlying
class that is being mocked rather that having to stub out everything. Is
that possible with FakeIt?Thanks,
JP—
Reply to this email directly or view it on GitHub
#1.
Eran
972-52-8387550
from fakeit.
I added spying functionality. It is now possible to spy an object by simply writing:
SomeClass obj;
Mock<SomeClass> spy(obj);
Here is the complete example:
struct SomeClass {
virtual int func1(int arg) {
return arg;
}
virtual int func2(int arg) {
return arg;
}
};
void useOriginalClassMethodIfNotStubbed() {
SomeClass obj;
Mock<SomeClass> spy(obj);
When(spy[&SomeClass::func1]).Return(0); // Override func1 to return 0.
SomeClass& i = spy.get();
ASSERT_EQUAL(0, i.func1(1)); // func1 should return 0
ASSERT_EQUAL(1, i.func2(1)); // func2 should stay unmocked
}
You can check for more examples at tests/spying_tests.cpp
from fakeit.
Related Issues (20)
- Overloaded function in derived class hides base class function HOT 5
- compiled error with c++17 in VS2019 HOT 4
- SIGSEGV when when mock with shared_ptr HOT 16
- complied error when mock with unique_ptr HOT 3
- exception with unique_ptr HOT 13
- Can't mock override with ref-qualifiers? HOT 5
- Colliding MockingContext ids when used in multiple translation units because of __COUNTER__ HOT 7
- Can't stub method with vector of unique_ptr parameter HOT 5
- Clang 14.0.6 compile error HOT 7
- Undefined sanitizer issue HOT 4
- Seems latest version 2.3.1 is not available on conan yet HOT 3
- fakeit from conan center doesn't get header with integration (e.g. header with gtest integration) HOT 5
- Quickstart spy example does not work as expected HOT 2
- Cannot verify 0 times invocations using RepeatedSequence HOT 4
- There are deprecated warnings on OSX with C++20 and C++23 HOT 3
- FakeIt and CppUTest HOT 3
- Verify Using QString gives bad_alloc HOT 2
- Missing .CoReturn method HOT 1
- Not working with local classes? HOT 1
- Stubbing method returning the vector of unique_ptr's generates the compile error. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fakeit.