Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Qt 5

You're reading from   Learn Qt 5 Build modern, responsive cross-platform desktop applications with Qt, C++, and QML

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781788478854
Length 346 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nicholas Sherriff Nicholas Sherriff
Author Profile Icon Nicholas Sherriff
Nicholas Sherriff
Arrow right icon
View More author details
Toc

Mocking

The unit tests we’ve written so far have all been pretty straightforward. While our Client class isn’t totally independent, its dependencies are all other data models and decorators that it can own and change at will. However, looking forward, we will want to persist client data in a database. Let's look at a few examples of how this can work and discuss how the design decisions we make impact the testability of the Client class.

Open up the scratchpad project and create a new header mocking.h file, where we’ll implement a dummy Client class to play around with.

mocking.h:

#ifndef MOCKING_H
#define MOCKING_H
#include <QDebug>
class Client { public: void save() { qDebug() << "Saving Client"; } };
#endif

In main.cpp, #include <mocking.h>, update the engine.load() line to load the default main.qml if...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime