[Interest] Fwd: Is there a way to mock the QNAM?
André Somers
andre at familiesomers.nl
Tue Sep 3 10:21:25 CEST 2013
Op 3-9-2013 10:17, Philipp Kursawe schreef:
> Great! Spacibo ;) I had not seen that in the docs.
It's an example of good API design, if you ask me: the public API to use
is not the same as the (protected) API to extend the class. These are
different tasks, and they should have a different API.
André
>
> On Tue, Sep 3, 2013 at 10:05 AM, Konstantin Tokarev <annulen at yandex.ru> wrote:
>>
>> 03.09.2013, 11:59, "Philipp Kursawe" <phil.kursawe at gmail.com>:
>>> I did not find a way to write unit-tests for my QNAM based code. My
>>> objects take a QNAM and perform operations with it like ::get() and
>>> ::post()
>>> Of course for Unit tests it should not really perform network
>>> requests. The usual way to test such things is to mock the network
>>> layer. However, since none of the get/post/put methods in QNAM are
>>> virtual I cannot override them :( My only solution for now is to use
>>> an interface based approach and not hand in the QNAM but rather an
>>> interface that looks like this:
>>> struct HttpClient {
>>> virtual QNetworkReply* get(const QNetworkRequest&) const;
>>> ...
>>> }
>>>
>>> This is then easily mockable.
>> You need to override createRequest(), it is virtual.
>>
>> --
>> Regards,
>> Konstantin
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
--
You like Qt?
I am looking for collegues to join me at i-Optics!
More information about the Interest
mailing list