First of all, you might want to define clean interfaces (meaning pure abstract classes) for your classes, so that mocking and exchanging them wouldn't be a problem, say IClientConnection
.
Then, you could declare your dependencies explicitly, i.e. either pass an IClientConnection
factory or an instance of an IClientConnection
to the NetworkServer
constructor.
In your test, you can now implement a mock of IClientConnection
and pass it or its factory (may also be an interface) to the constructor in the test. Perhaps, you might want to use a smart pointer (shared_ptr or something native to Qt), so that automatic resource deallocation would minimize bugs.
If your software grows and you find yourself writing a lot of manual dependency injection, you might use a DI library. I've recently started a review of some of the available C++ DI libraries.
Finally, you might get far by mocking your dependencies using a mocking framework, such as googlemock.