Is there a way to mock a sdbus::IConnection? #163
-
Hi all, I'm searching for a way to mock completely a sdbus::IConnection to be able to test an object that is extended from an adaptor without having a real dbus connection? I did a mock class like this one:
Without providing any EXPECT_CALL from this mock object I'm getting "[org.freedesktop.DBus.Error.InvalidArgs] Connection is not a real sdbus-c++ connection (Invalid argument)" since it's a mock connection. Would there be an other strategy to achieve what I am searching for? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@dakhouya No, there is no way to do that.
Additionally, on top of that, you can test the integration of sdbus-c++ classes, your object class and decoupled logic in higher-level integration tests. |
Beta Was this translation helpful? Give feedback.
@dakhouya No, there is no way to do that.
Connection
s have internal base classes. The adaptor/proxy classes are coupled to real sdbus-c++ connection, by design. However, you can decouple the server logic from your object class and test it in unit tests independently from sdbus-c++. A few approaches come to my mind:template<class Base> class MyObject : public Base {...};
, where in production you'd instantiate it with realsdbus::AdaptorInterfaces
template class as Base template argument, in tests you'd provide a dummy class as Base template argument. In this case you can mocksdbus::IConnection
and push it intoMyObject
constructor.