QQuickTest Namespace

The QQuickTest namespace contains all the functions and macros related to Qt Quick Test. More...

Header: #include <QQuickTest>

Macros

QUICK_TEST_MAIN(name)
QUICK_TEST_MAIN_WITH_SETUP(name, QuickTestSetupClass)

Detailed Description

See the Introduction to Qt Quick Test for information about how to write Qt Quick unit tests.

To link to the Qt Quick Test C++ library, see Qt Quick Test C++ API.

See also Executing C++ Before QML Tests.

Macro Documentation

QUICK_TEST_MAIN(name)

Sets up the entry point for a Qt Quick Test application. The name argument uniquely identifies this set of tests.


  #include <QtQuickTest>
  QUICK_TEST_MAIN(example)

Note: The macro assumes that your test sources are in the current directory, unless the QUICK_TEST_SOURCE_DIR environment variable is set.

See also QUICK_TEST_MAIN_WITH_SETUP() and Running Qt Quick Tests.

QUICK_TEST_MAIN_WITH_SETUP(name, QuickTestSetupClass)

Sets up the entry point for a Qt Quick Test application. The name argument uniquely identifies this set of tests.

This macro is identical to QUICK_TEST_MAIN(), except that it takes an additional argument QuickTestSetupClass, a pointer to a QObject-derived class. With this class it is possible to define additional setup code to execute before running the QML test.

Note: The macro assumes that your test sources are in the current directory, unless the QUICK_TEST_SOURCE_DIR environment variable is set.

The following snippet demonstrates the use of this macro:


  // tst_mytest.cpp
  #include <QtQuickTest>
  #include <QQmlEngine>
  #include <QQmlContext>

  class Setup : public QObject
  {
      Q_OBJECT

  public:
      Setup() {}

  public slots:
      void qmlEngineAvailable(QQmlEngine *engine)
      {
          engine->rootContext()->setContextProperty("myContextProperty", QVariant(true));
      }
  };

  QUICK_TEST_MAIN_WITH_SETUP(mytest, Setup)

  #include "tst_mytest.moc"

See also QUICK_TEST_MAIN() and Running Qt Quick Tests.