2

I'm trying to solve my unit testing problem. I have a class with a QTcpSocket object in it. This class has derived from the QObject to use the signal/slot system and the socket object is used inside slots. I have tried to mock (gmock) this socket object, but I couldn't find any solution to incorporate the mock object to my class.

I cannot do this through a template, because the MOC compiler doesn't work with templates. And I cannot create a general interface for the QTcpSocket and my mock class. Though the QAbstractSocket has virtual methods, it has non-virtual methods like waitForReadyRead() too. That confuse me.

273K
  • 29,503
  • 10
  • 41
  • 64
  • What means "mock this socket object" and "incorporate the mock object to my class"? – vahancho Jul 03 '18 at 10:34
  • "mock this socket object" - create a class that emulates the QTcpSocket behaviour (for example with a name like a TcpSocketMock) , "incorporate the mock object to my class" - inject a TcpSocketMock object to the class that I want to test (that class is a 'driver' for a device that is connected by a tcp connection) – Олег Юрченко Jul 04 '18 at 07:36
  • @ОлегЮрченко, Have you found a solution to this type of problem? – Saeed Masoomi Oct 30 '22 at 14:12

0 Answers0