O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test init and cleanup

The QtTest framework provides special functionality, according to which, if two slots called init and cleanup are added to the test case class, they are invoked automatically, respectively, before and after every test method of the test case class.

For example, if we want to create an instance of the GroceryItems entity before each test and make sure it is destroyed after the test has finished, we can do the following:

// tst_add_grocery_item.cpp...class Usecases_add_grocery_item : public QObject{...private Q_SLOTS:    void init();    void cleanup();private:    entities::GroceryItems* m_groceryItems;...void Usecases_add_grocery_item::init(){    qDebug() << "init";    m_groceryItems = new entities::GroceryItems(this); auto groceryItemsRepoDummy ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required