Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > a6711891ce757817bba854bf3f25205a > files > 2298

qtjambi-doc-4.3.3-3mdv2008.1.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /home/gvatteka/dev/qt-4.3/doc/src/qtestlib.qdoc -->
<head>
  <title>QTestLib Manual</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1 align="center">QTestLib Manual<br /><small></small></h1>
<a name="qtestlib"></a><p>The <a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> framework, provided by Trolltech, is a tool for unit testing Qt based applications and libraries. <a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> provides all the functionality commonly found in unit testing frameworks as well as extensions for testing graphical user interfaces.</p>
<p>Table of contents:</p>
<ul><li><a href="#qtestlib-features">QTestLib Features</a></li>
<li><a href="#qtestlib-api">QTestLib API</a></li>
<li><a href="#using-qtestlib">Using QTestLib</a></li>
<ul><li><a href="#creating-a-test">Creating a test</a></li>
<li><a href="#building-a-test">Building a Test</a></li>
<li><a href="#qtestlib-command-line-arguments">QTestLib Command Line Arguments</a></li>
<ul><li><a href="#syntax">Syntax</a></li>
<li><a href="#options">Options</a></li>
</ul>
</ul>
</ul>
<a name="qtestlib-features"></a>
<h3>QTestLib Features</h3>
<p><a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> is designed to ease the writing of unit tests for Qt based applications and libraries:</p>
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
<thead><tr valign="top" class="qt-style"><th>Feature</th><th>Details</th></tr></thead>
<tr valign="top" class="odd"><td><b>Lightweight</b></td><td><a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> consists of about 6000 lines of code and 60 exported symbols.</td></tr>
<tr valign="top" class="even"><td><b>Self-contained</b></td><td><a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> requires only a few symbols from the Qt Core library for non-gui testing.</td></tr>
<tr valign="top" class="odd"><td><b>Rapid testing</b></td><td><a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> needs no special test-runners; no special registration for tests.</td></tr>
<tr valign="top" class="even"><td><b>Data-driven testing</b></td><td>A test can be executed multiple times with different test data.</td></tr>
<tr valign="top" class="odd"><td><b>Basic GUI testing</b></td><td><a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> offers functionality for mouse and keyboard simulation.</td></tr>
<tr valign="top" class="even"><td><b>IDE friendly</b></td><td><a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> outputs messages that can be interpreted by Visual Studio and KDevelop.</td></tr>
<tr valign="top" class="odd"><td><b>Thread-safety</b></td><td>The error reporting is thread safe and atomic.</td></tr>
<tr valign="top" class="even"><td><b>Type-safety</b></td><td>Extensive use of templates prevent errors introduced by implicit type casting.</td></tr>
<tr valign="top" class="odd"><td><b>Easily extendable</b></td><td>Custom types can easily be added to the test data and test output.</td></tr>
</table></p>
<p>Note: For higher-level GUI and application testing needs, please see the Qt testing products provided by Trolltech partners</tt>.</p>
<a name="qtestlib-api"></a>
<h3>QTestLib API</h3>
<p>All public methods are in the <tt>QTest</tt> namespace. In addition, the <tt>QSignalSpy</tt> class provides easy introspection for Qt's signals and slots.</p>
<a name="using-qtestlib"></a>
<h3>Using QTestLib</h3>
<a name="creating-a-test"></a>
<h4>Creating a test</h4>
<p>To create a test, subclass <a href="core/QObject.html"><tt>QObject</tt></a> and add one or more private slots to it. Each private slot is a testfunction in your test. QTest::qExec() can be used to execute all testfunctions in the test object.</p>
<p>In addition, there are four private slots that are <i>not</i> treated as testfunctions. They will be executed by the testing framework and can be used to initialize and clean up either the entire test or the current test function.</p>
<ul>
<li><tt>initTestCase()</tt> will be called before the first testfunction is executed.</li>
<li><tt>cleanupTestCase()</tt> will be called after the last testfunction was executed.</li>
<li><tt>init()</tt> will be called before each testfunction is executed.</li>
<li><tt>cleanup()</tt> will be called after every testfunction.</li>
</ul>
<p>If <tt>initTestCase()</tt> fails, no testfunction will be executed. If <tt>init()</tt> fails, the following testfunction will not be executed, the test will proceed to the next testfunction.</p>
<p>Example:</p>
<pre>    class MyFirstTest: public QObject
    {
        Q_OBJECT
    private slots:
        void initTestCase()
        { qDebug(&quot;called before everything else&quot;); }
        void myFirstTest()
        { QVERIFY(1 == 1); }
        void mySecondTest()
        { QVERIFY(1 != 2); }
        void cleanupTestCase()
        { qDebug(&quot;called after myFirstTest and mySecondTest&quot;); }
    };</pre>
<p>For more examples, refer to the <a href="qtestlib-tutorial.html"><tt>QTestLib Tutorial</tt></a>.</p>
<a name="building-a-test"></a>
<h4>Building a Test</h4>
<p>If you are using <tt>qmake</tt> as your build tool, just add the following to your project file:</p>
<pre>    CONFIG += qtestlib</pre>
<p>If you are using other buildtools, make sure that you add the location of the <a href="qtestlib-manual.html#qtestlib"><tt>QTestLib</tt></a> header files to your include path (usually <tt>include/QtTest</tt> under your Qt installation directory). If you are using a release build of Qt, link your test to the <tt>QtTest</tt> library. For debug builds, use <tt>QtTest_debug</tt>.</p>
<p>See Writing a Unit Test</tt> for a step by step explanation.</p>
<a name="qtestlib-command-line-arguments"></a>
<h4>QTestLib Command Line Arguments</h4>
<a name="syntax"></a>
<h5>Syntax</h5>
<p>The syntax to execute an autotest takes the following simple form:</p>
<pre>    testname [options] [testfunctions[:testdata]]...</pre>
<p>Substitute <tt>testname</tt> with the name of your executable. <tt>testfunctions</tt> can contain names of testfunctions to be executed. If no <tt>testfunctions</tt> are passed, all tests are run. If the name of an entry in the test function's test data is appended to the test function's name, the test function will be run only with that testdata.</p>
<p>For example:</p>
<pre>        /myTestDirectory$ testQString toUpper</pre>
<p>Runs the test function called <tt>toUpper</tt> with all available test data.</p>
<pre>        /myTestDirectory$ testQString toUpper toInt:zero</pre>
<p>Runs the <tt>toUpper</tt> test function with all available test data, and the <tt>toInt</tt> test function with the testdata called <tt>zero</tt> (if the specified test data doesn't exist, the associated test will fail).</p>
<pre>        /myTestDirectory$ testMyWidget -vs -eventdelay 500</pre>
<p>Runs the testMyWidget function test, outputs every signal emission and waits 500 milliseconds after each simulated mouse/keyboard event.</p>
<a name="options"></a>
<h5>Options</h5>
<p>The following command line arguments are understood:</p>
<ul>
<li><tt>-help</tt> <br /> outputs the possible command line arguments and give some useful help.</li>
<li><tt>-functions</tt> <br /> outputs all test functions available in the test.</li>
<li><tt>-o</tt> <i>filename</i> <br /> write output to the specified file, rather than to standard output</li>
<li><tt>-silent</tt> <br /> silent output, only shows warnings, failures and minimal status messages</li>
<li><tt>-v1</tt> <br /> verbose output; outputs information on entering and exiting test functions.</li>
<li><tt>-v2</tt> <br /> extended verbose output; also outputs each <tt>QCOMPARE</tt> and <tt>QVERIFY</tt></li>
<li><tt>-vs</tt> <br /> outputs every signal that gets emitted</li>
<li><tt>-xml</tt> <br /> outputs XML formatted results instead of plain text</li>
<li><tt>-lightxml</tt> <br /> outputs results as a stream of XML tags</li>
<li><tt>-eventdelay</tt> <i>ms</i> <br /> if no delay is specified for keyboard or mouse simulation (<tt>QTest::keyClick</tt>, <tt>QTest::mouseClick</tt> etc.), the value from this parameter (in milliseconds) is substituted.</li>
<li><tt>-keydelay</tt> <i>ms</i> <br /> like -eventdelay, but only influences keyboard simulation and not mouse simulation.</li>
<li><tt>-mousedelay</tt> <i>ms</i> <br /> like -eventdelay, but only influences mouse simulation and not keyboard simulation.</li>
<li><tt>-keyevent-verbose</tt> <br /> output more verbose output for keyboard simulation</li>
<li><tt>-maxwarnings</tt> <i>numberBR</i> sets the maximum number of warnings to output. 0 for unlimited, defaults to 2000.</li>
</ul>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2007 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt Jambi </div></td>
</tr></table></div></address></body>
</html>