Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

New-Unit-Test-Structure: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
== Introduction ==
== Introduction ==


This article focuses on the structure beneath <code>tests/auto/</code> so that you know exactly where to put your tests.
This article focuses on the structure beneath <code>tests/auto/</code> so that you know exactly where to put your tests.


== Autotest Structure ==
== Autotest Structure ==


Whenever something is submitted to &quot;Gerrit&amp;quot;:https://codereview.qt.io/, it will be tested by [[CI-Configurations|CI System]].
Whenever something is submitted to "Gerrit":https://codereview.qt.io/, it will be tested by [[CI-Configurations|CI System]].


The testing is done by executing tests located under &lt;code&amp;gt;tests/auto/&amp;lt;/code&amp;gt;.
The testing is done by executing tests located under <code>tests/auto/</code>.


Questions to ask:
Questions to ask:
Line 27: Line 27:
# It is easy to test a certain functional area in isolation.
# It is easy to test a certain functional area in isolation.


Consider the &lt;code&amp;gt;QMutex&amp;lt;/code&amp;gt; class for example. This resides in &lt;code&amp;gt;src/corelib/thread/&amp;lt;/code&amp;gt; and the corresponding test is located under &lt;code&amp;gt;tests/auto/corelib/thread/qmutex/&amp;lt;/code&amp;gt;.
Consider the <code>QMutex</code> class for example. This resides in <code>src/corelib/thread/</code> and the corresponding test is located under <code>tests/auto/corelib/thread/qmutex/</code>.


As another example, let's say that you have made a change that is likely to affect code under &lt;code&amp;gt;src/corelib/&amp;lt;/code&amp;gt; only. You can now execute a recursive test runner (such as '&lt;code&amp;gt;make check&amp;lt;/code&amp;gt;') locally from &lt;code&amp;gt;tests/auto/corelib/&amp;lt;/code&amp;gt; and thus save time by running only the tests that are likely to be sensitive to the change. (Of course, at some point, a full test run needs to be executed, but that can happen less frequently.)
As another example, let's say that you have made a change that is likely to affect code under <code>src/corelib/</code> only. You can now execute a recursive test runner (such as '<code>make check</code>') locally from <code>tests/auto/corelib/</code> and thus save time by running only the tests that are likely to be sensitive to the change. (Of course, at some point, a full test run needs to be executed, but that can happen less frequently.)


== Current state ==
== Current state ==


By the time of this writing, test restructuring has been done for QtBase only (and there is still a bit<br />cleanup to be done). The principle should be applied to other modules as well, and will be the responsibility<br />of the Qt community as a whole.
By the time of this writing, test restructuring has been done for QtBase only (and there is still a bit
cleanup to be done). The principle should be applied to other modules as well, and will be the responsibility
of the Qt community as a whole.


The test structure in QtBase currently looks essentially like this:
The test structure in QtBase currently looks essentially like this:


<code><br />auto<br /> corelib<br /> animation<br /> qabstractanimation &lt;— tests for 'qabstractanimation' go here<br /> qanimationgroup<br /> <br /> <br /> thread<br /> qmutex &lt;— tests for 'qmutex' go here<br /> qsemaphore<br /> <br /> <br /> dbus<br /> gui<br /> integrationtests<br /> network<br /> opengl<br /> other<br /> sql<br /> testlib<br /> tools<br /> xml<br /> v8<br /></code>
<code>
auto
corelib
animation
qabstractanimation <— tests for 'qabstractanimation' go here
qanimationgroup
thread
qmutex <— tests for 'qmutex' go here
qsemaphore
dbus
gui
integrationtests
network
opengl
other
sql
testlib
tools
xml
v8
</code>

Revision as of 10:27, 25 February 2015


New Unit Test Structure for Qt

Introduction

This article focuses on the structure beneath

tests/auto/

so that you know exactly where to put your tests.

Autotest Structure

Whenever something is submitted to "Gerrit":https://codereview.qt.io/, it will be tested by CI System.

The testing is done by executing tests located under

tests/auto/

.

Questions to ask:

  • Where to put the test for my new class?
  • Where is the test for the class containing my new function?

The proposed answer to these questions is:

The directory structure of the tests should resemble the directory structure of the Qt source itself as much as possible.

The structural resemblance has two advantages:

  1. It is easy to locate the test for a particular class.
  2. It is easy to test a certain functional area in isolation.

Consider the

QMutex

class for example. This resides in

src/corelib/thread/

and the corresponding test is located under

tests/auto/corelib/thread/qmutex/

. As another example, let's say that you have made a change that is likely to affect code under

src/corelib/

only. You can now execute a recursive test runner (such as '

make check

') locally from

tests/auto/corelib/

and thus save time by running only the tests that are likely to be sensitive to the change. (Of course, at some point, a full test run needs to be executed, but that can happen less frequently.)

Current state

By the time of this writing, test restructuring has been done for QtBase only (and there is still a bit cleanup to be done). The principle should be applied to other modules as well, and will be the responsibility of the Qt community as a whole.

The test structure in QtBase currently looks essentially like this:

auto
 corelib
 animation
 qabstractanimation < tests for 'qabstractanimation' go here
 qanimationgroup
 
 
 thread
 qmutex < tests for 'qmutex' go here
 qsemaphore
 
 
 dbus
 gui
 integrationtests
 network
 opengl
 other
 sql
 testlib
 tools
 xml
 v8