Comments (3)
Thanks @paulreimer for the questions
-
Can we still use the automatic mock generation?
- Unfortunatelly not out of the box as automatic mock injection requres GMocks
- You could still use it if you provide some sort of traits for the mocks, though
template<class> struct Mock; template<> struct Mock<MockPacketStream> { MOCK_CONST_METHOD1(GetPacket, const Packet*(size_t packet_number)); MOCK_CONST_METHOD0(NumberOfPackets, size_t()); };
And this automatic mocks injection when resolve a type T
return Mock<T>();
-
Can we still use
GUnit.GMake
? (since we are using derived class template args, notstatic_cast<iface&>
)
- Sort of, as described above
- Can we still use
Boost.DI
? (I know, a question for a different repo)
-
Yes, no issues here
example::example(ConcretePacketStream &); // no problems here, wiring not even needed
With templates no issues too
template<class T = class Stream> example::example(T stream);
di::bind<class Stream>.to<ConcretePacketStream>()
One thing, which might be useful when using templates is to avoid writing macros, though.
That can be done by defining an interface instead and using GMock, automatic mock injection and DI without loosing performance at all as it will be injected via templates.
struct IStreamJustForTesting {
virtual ~IStreamJustForTesting () = default;
virtual void AppendPacket(Packet* new_packet) = 0;
virtual const Packet* GetPacket(size_t packet_number) const =0;
virtual size_t NumberOfPackets() const = 0;
};
di::bind<class Stream>.to<GMock<IStreamJustForTesting>()
from gunit.
OK, sounds good. I'm still trying to understand the first "automatic mock injection" part. Actually my question was more about the "automatic mock generation" part (e.g. avoiding macros), looks like it is possible as in the final example. So, at least we can define the interface in C++ (even if the concrete class doesn't inherit it) and avoid the MOCK_*
macros (yay!).
Also just to check if I understand correctly, but in the final example then any mocks generated for IStreamJustForTesting
will have dynamic dispatch (and use static_cast
), but this only applies to the mocks and the production implementations do not need that interface? (and this is the price we pay -- at test time -- for avoiding the macros)
from gunit.
Right, Macros might be avoided with interfaces and GMock.
Yes, exactly. No cost in production but dynamic dispatch in testing.
from gunit.
Related Issues (20)
- Unable to compile with googletest master branch, since de5be0eb28b74ecd6335e3bd61d9dc8914ce0e57 HOT 1
- make[2]: *** No rule to make target 'libs'. Stop. HOT 1
- test/GSteps.cpp: -Werror build failure on ignored-qualifiers
- IS C++20 concepts support on the roadmap?
- Update to googletest 1.10.x HOT 2
- Test results in cucumber json formatter
- Test crashing when feature is defined in more than one file and there are scenarios in same the line number HOT 1
- README.md: Motivation example code fails compilation due to incorrect fixture name.
- std::move and std::static_pointer_cast of mock objects cause segmentation faults HOT 1
- Is there any way to mock function call operator?
- Fix for Gherkin's localization
- Expose SHOULD("XXX") sub-targets explicitly callable from the shell HOT 3
- Multiple inheritance in interfaces leads to segmentation faults with GMock HOT 3
- Add ability to show GUnit Tests in gtest_list_tests HOT 1
- error at root CMakeList.txt L:81 and Line:89 in test function HOT 1
- GAssert: Support for matchers in ASSERT/EXPECT macro.
- SetUp and TearDown being called twice
- [REQUEST] Next release planned? HOT 1
- Request: New gunit release 1.13.0 HOT 1
- Request: Release gunit 1.14.0 HOT 1
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 gunit.