Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates > by-pkgid > 6e2327ca1c896c6d674ae53117299f21 > files > 438

qtdeclarative5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qtquicktest-index.qdoc -->
  <title>Qt Quick Test 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td >Qt Quick Test</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.12.6 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#introduction">Introduction</a></li>
<li class="level1"><a href="#running-tests">Running Tests</a></li>
<li class="level1"><a href="#executing-c-before-qml-tests">Executing C++ Before QML Tests</a></li>
<li class="level1"><a href="#licenses">Licenses</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick Test</h1>
<span class="subtitle"></span>
<!-- $$$qtquicktest-index.html-description -->
<div class="descr"> <a name="details"></a>
<a name="introduction"></a>
<h2 id="introduction">Introduction</h2>
<p>Qt Quick Test is a unit test framework for QML applications. Test cases are written as JavaScript functions within a TestCase type:</p>
<pre class="qml">



</pre>
<p>Functions whose names start with <code>test_</code> are treated as test cases to be executed. See the documentation for the TestCase and SignalSpy types for more information on writing test cases.</p>
<p><b>Note: </b>There is no binary compatibility guarantee for the Qt Quick Test module. This means that an application that uses Qt Quick Test is only guaranteed to work with the Qt version it was developed against. However, source compatibility is guaranteed.</p><a name="running-tests"></a>
<h2 id="running-tests">Running Tests</h2>
<p>Test cases are launched by a C++ harness that consists of the following code:</p>
<pre class="cpp">

  <span class="preprocessor">#include &lt;QtQuickTest/quicktest.h&gt;</span>
  QUICK_TEST_MAIN(example)

</pre>
<p>Where &quot;example&quot; is the identifier to use to uniquely identify this set of tests. Finally, add <code>CONFIG += qmltestcase</code> to the project file:</p>
<pre class="cpp plain">

  TEMPLATE = app
  TARGET = tst_example
  CONFIG += warn_on qmltestcase
  SOURCES += tst_example.cpp

</pre>
<p>The test harness scans the specified source directory recursively for &quot;tst_*.qml&quot; files. If <code>QUICK_TEST_SOURCE_DIR</code> is not defined, then the current directory will be scanned when the harness is run. Other *.qml files may appear for auxillary QML components that are used by the test.</p>
<p>The <code>-input</code> command-line option can be set at runtime to run test cases from a different directory. This may be needed to run tests on a target device where the compiled-in directory name refers to a host. For example:</p>
<pre class="cpp plain">

  tst_example -input /mnt/SDCard/qmltests

</pre>
<p>It is also possible to run a single file using the <code>-input</code> option. For example:</p>
<pre class="cpp plain">

  tst_example -input data/test.qml

</pre>
<pre class="cpp plain">

  tst_example -input &lt;full_path&gt;/test.qml

</pre>
<p><b>Note: </b>Specifying the full path to the qml test file is for example needed for shadow builds.</p><p>If your test case needs QML imports, then you can add them as <code>-import</code> options to the test program command-line.</p>
<p>If <code>IMPORTPATH</code> is specified in your .pro file, each import path added to <code>IMPORTPATH</code> will be passed as a command-line argument when the test is run using &quot;make check&quot;:</p>
<pre class="cpp plain">

  IMPORTPATH += $$PWD/../imports/my_module1 $$PWD/../imports/my_module2

</pre>
<p>The <code>-functions</code> command-line option will return a list of the current tests functions. It is possible to run a single test function using the name of the test function as an argument. For example:</p>
<pre class="cpp plain">

  tst_example Test_Name::function1

</pre>
<p>The <code>-help</code> command-line option will return all the options available.</p>
<pre class="cpp plain">

  tst_example -help

</pre>
<a name="executing-c-before-qml-tests"></a>
<h2 id="executing-c-before-qml-tests">Executing C++ Before QML Tests</h2>
<p>To execute C++ code before any of the QML tests are run, the <code>QUICK_TEST_MAIN_WITH_SETUP</code> macro can be used. This can be useful for setting context properties on the QML engine, amongst other things.</p>
<p>The macro is identical to <code>QUICK_TEST_MAIN</code>, except that it takes an additional <code>QObject*</code> argument. The test framework will call slots and invokable functions with the following names:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Name</th><th >Purpose</th><th >Since</th></tr></thead>
<tr valign="top" class="odd"><td >void applicationAvailable()</td><td >Called right after the QApplication object was instantiated. Use this function to perform setup that does not require a QQmlEngine instance.</td><td >Qt 5.12</td></tr>
<tr valign="top" class="even"><td >void qmlEngineAvailable(QQmlEngine*)</td><td >Called when the QML engine is available. Any import paths, plugin paths, and extra file selectors will have been set on the engine by this point.<p>This function is called once for each QML test file, so any arguments are unique to that test. For example, this means that each QML test file will have its own QML engine.</p>
<p>This function can be used to register QML types and add import paths, amongst other things.</p>
</td><td >Qt 5.11</td></tr>
<tr valign="top" class="odd"><td >void cleanupTestCase()</td><td >Called right after the test execution has finished. Use this function to clean up before everything will start to be destructed.</td><td >Qt 5.12</td></tr>
</table></div>
<p>The following example demonstrates how the macro can be used to set context properties on the QML engine:</p>
<pre class="cpp">

  <span class="preprocessor">#include &lt;QtQuickTest&gt;</span>
  <span class="preprocessor">#include &lt;QQmlEngine&gt;</span>
  <span class="preprocessor">#include &lt;QQmlContext&gt;</span>

  <span class="keyword">class</span> Setup : <span class="keyword">public</span> <span class="type">QObject</span>
  {
      Q_OBJECT

  <span class="keyword">public</span>:
      Setup() {}

  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> qmlEngineAvailable(<span class="type">QQmlEngine</span> <span class="operator">*</span>engine)
      {
          engine<span class="operator">-</span><span class="operator">&gt;</span>rootContext()<span class="operator">-</span><span class="operator">&gt;</span>setContextProperty(<span class="string">&quot;myContextProperty&quot;</span><span class="operator">,</span> <span class="type">QVariant</span>(<span class="keyword">true</span>));
      }
  };

  QUICK_TEST_MAIN_WITH_SETUP(mytest<span class="operator">,</span> Setup)

  <span class="preprocessor">#include &quot;tst_mytest.moc&quot;</span>

</pre>
<p>The <code>.moc</code> include is based on the file name of the <code>.cpp</code> file. For example, in the example above, the <code>.cpp</code> file is named <code>tst_mytest.cpp</code>. If the file was named <code>MyTest.cpp</code>, the include would be:</p>
<pre class="cpp">

  <span class="preprocessor">#include &quot;MyTest.moc&quot;</span>

</pre>
<a name="licenses"></a>
<h2 id="licenses">Licenses</h2>
<p>Qt Quick Tests is available under commercial licenses from The Qt Company. In addition, it is available under free software licenses. Since Qt 5.4, these free software licenses are GNU Lesser General Public License, version 3, or the GNU General Public License, version 2. See Qt Licensing for further details.</p>
</div>
<!-- @@@qtquicktest-index.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>