Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 5ab010e37991249ab4adaa24d6e39c6e > files > 192

qt5-qtdoc-5.1.1-2.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qtquicktest.qdoc -->
  <title>Qt Quick Test Reference Documentation | QtDoc 5.1</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader"></div>
<div class="content">
<div class="line">
<div class="content mainContent">
<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>
</ul>
</div>
<h1 class="title">Qt Quick Test Reference Documentation</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-qtquicktest.html-description -->
<div class="descr"> <a name="details"></a>
<a name="introduction"></a>
<h2>Introduction</h2>
<p>QtQuickTest is a unit test framework for QML applications. Test cases are written as JavaScript functions within a TestCase type:</p>
<pre class="cpp">import <span class="type">QtQuick</span> <span class="number">2.0</span>
import <span class="type">QtTest</span> <span class="number">1.0</span>

TestCase {
    name: <span class="string">&quot;MathTests&quot;</span>

    function test_math() {
        compare(<span class="number">2</span> <span class="operator">+</span> <span class="number">2</span><span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="string">&quot;2 + 2 = 4&quot;</span>)
    }

    function test_fail() {
        compare(<span class="number">2</span> <span class="operator">+</span> <span class="number">2</span><span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="string">&quot;2 + 2 = 5&quot;</span>)
    }
}</pre>
<p>Functions whose names start with <tt>test_</tt> 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>
<a name="running-tests"></a>
<h2>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. You should add <tt>CONFIG += qmltestcase</tt>. for example:</p>
<pre class="cpp">TEMPLATE <span class="operator">=</span> app
TARGET <span class="operator">=</span> tst_example
CONFIG <span class="operator">+</span><span class="operator">=</span> warn_on qmltestcase
SOURCES <span class="operator">+</span><span class="operator">=</span> tst_example<span class="operator">.</span>cpp</pre>
<p>The test harness scans the specified source directory recursively for &quot;tst_*.qml&quot; files. If <tt>QUICK_TEST_SOURCE_DIR</tt> 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 <tt>-input</tt> 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">tst_example <span class="operator">-</span>input <span class="operator">/</span>mnt<span class="operator">/</span>SDCard<span class="operator">/</span>qmltests</pre>
<p>It is also possible to run a single file using the <tt>-input</tt> option. For example:</p>
<pre class="cpp">tst_example <span class="operator">-</span>input data<span class="operator">/</span>test<span class="operator">.</span>qml</pre>
<pre class="cpp">tst_example <span class="operator">-</span>input <span class="operator">&lt;</span>full_path<span class="operator">&gt;</span><span class="operator">/</span>test<span class="operator">.</span>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 <tt>-import</tt> options to the test program command-line by adding the following line to your .pro file:</p>
<pre class="cpp">IMPORTPATH <span class="operator">+</span><span class="operator">=</span> $$PWD<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>imports<span class="operator">/</span>my_module1 $$PWD<span class="operator">/</span><span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>imports<span class="operator">/</span>my_module2</pre>
<p>The <tt>-functions</tt> 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">tst_example Test_Name<span class="operator">::</span>function1</pre>
<p>The <tt>-help</tt> command-line option will return all the options available.</p>
<pre class="cpp">tst_example <span class="operator">-</span>help</pre>
</div>
<!-- @@@qtquick-qtquicktest.html -->
</div>
</div>
</div>
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      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.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>