Skip to content

Is there a way to mock a sdbus::IConnection? #163

Answered by sangelovic
dakhouya asked this question in Q&A
Discussion options

You must be logged in to vote

@dakhouya No, there is no way to do that. Connections 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:

  • Simply, turn your object class into a template class (template<class Base> class MyObject : public Base {...};, where in production you'd instantiate it with real sdbus::AdaptorInterfaces template class as Base template argument, in tests you'd provide a dummy class as Base template argument. In this case you can mock sdbus::IConnection and push it into MyObject constructor.
  • O…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dakhouya
Comment options

Answer selected by dakhouya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants