[Interest] Mocking Network calls in code using QNetworkAccessManager
Shantanu Tushar
shaan7in at gmail.com
Thu May 18 12:35:30 CEST 2017
Hi,
In one of the unit tests that I am trying to write, I call a function
that makes a get() call using a QNetworkAccessManager that I pass to
it. It looks something like this-
bool trackEvent(QString event, QNetworkAccessManager *nam);
However, I do not want actual HTTP calls being made during the unit
test, so I thought I'll write a FakeNetworkAccessManager and pass that
(where I write a mock get()). The issue is that the get() on
QNetworkAccessManager is not virtual, so at the end my mock get() is
useless.
Any recommendations on how to do I achieve the unit test without
needing network access?
Cheers,
--
Shantanu Tushar (UTC +0530)
shantanu.io
More information about the Interest
mailing list