Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qttest-best-practices.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2019 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qttest-best-practices.html
6
7
\title Qt Test Best Practices
8
9
\brief Guidelines for creating Qt tests.
10
11
We recommend that you add Qt tests for bug fixes and new features. Before
12
you try to fix a bug, add a \e {regression test} (ideally automatic) that
13
fails before the fix, exhibiting the bug, and passes after the fix. While
14
you're developing new features, add tests to verify that they work as
15
intended.
16
17
Conforming to a set of coding standards will make it more likely for
18
Qt autotests to work reliably in all environments. For example, some
19
tests need to read data from disk. If no standards are set for how this
20
is done, some tests won't be portable. For example, a test that assumes
21
its test-data files are in the current working directory only works for
22
an in-source build. In a shadow build (outside the source directory), the
23
test will fail to find its data.
24
25
The following sections contain guidelines for writing Qt tests:
26
27
\list
28
\li \l {General Principles}
29
\li \l {Writing Reliable Tests}
30
\li \l {Improving Test Output}
31
\li \l {Writing Testable Code}
32
\li \l {Setting up Test Machines}
33
\endlist
34
35
The advice on \l {Qt Test Security Considerations}{Security Considerations}
36
should be borne in mind alongside those best practices.
37
38
\section1 General Principles
39
40
The following sections provide general guidelines for writing unit tests:
41
42
\list
43
\li \l {Verify Tests}
44
\li \l {Give Test Functions Descriptive Names}
45
\li \l {Write Self-contained Test Functions}
46
\li \l {Avoid external dependencies}
47
\li \l {Test the Full Stack}
48
\li \l {Make Tests Complete Quickly}
49
\li \l {Use Data-driven Testing}
50
\li \l {Use Coverage Tools}
51
\li \l {Select Appropriate Mechanisms to Exclude Tests}
52
\li \l {Avoid Q_ASSERT}
53
\endlist
54
55
\section2 Verify Tests
56
57
Write and commit your tests along with your fix or new feature on a new
58
branch. Once you're done, you can check out the branch on which your work
59
is based, and then check out into this branch the test-files for your new
60
tests. This enables you to verify that the tests do fail on the prior
61
branch, and therefore actually do catch a bug or test a new feature.
62
63
For example, the workflow to fix a bug in the \c QDateTime class could be
64
like this if you use the Git version control system:
65
66
\list 1
67
\li Create a branch for your fix and test:
68
\c {git checkout -b fix-branch dev}
69
\li Write a test and fix the bug.
70
\li Build and test with both the fix and the new test, to verify that
71
the new test passes with the fix.
72
\li Add the fix and test to your branch:
73
\c {git add tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp src/corelib/time/qdatetime.cpp}
74
\li Commit the fix and test to your branch:
75
\c {git commit -m 'Fix bug in QDateTime'}
76
\li To verify that the test actually catches something for which you
77
needed the fix, checkout the branch you based your own branch on:
78
\c {git checkout dev}
79
\li Checkout only the test file from the fix branch:
80
\c {git checkout fix-branch -- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp}
81
82
The rest of the source tree stays on dev, without the fix, but with
83
the new test ready to try on it.
84
\li Build and run the test to verify that it fails on dev, and therefore
85
does indeed catch a bug.
86
\li You can now return to the fix branch:
87
\c {git checkout fix-branch}
88
\li Alternatively, you can restore your work tree to a clean state on
89
dev: \c{git checkout HEAD -- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp}
90
\endlist
91
92
When you're reviewing a change, you can adapt this workflow to check that
93
the change does indeed come with a test for a problem it does fix.
94
95
\section2 Give Test Functions Descriptive Names
96
97
Naming test cases is important. The test name appears in the failure report
98
for a test run. For data-driven tests, the name of the data row also appears
99
in the failure report. Good names can give those reading the report a first
100
indication of what has gone wrong.
101
102
Test function names should make it obvious what the function is trying to
103
test. Do not simply use the bug-tracking identifier, because the identifiers
104
become obsolete if the bug-tracker is replaced. Also, developers working
105
offline cannot access your bug-tracker and some bug-trackers may not be
106
accessible to all users. When the bug report may be of interest to later
107
readers of the test code, you can mention it in a comment alongside a
108
relevant part of the test.
109
110
Likewise, when writing data-driven tests, give descriptive names to the
111
test-cases, that indicate what aspect of the functionality each focuses on.
112
Do not simply number the test-case, or use bug-tracking identifiers. Someone
113
reading the test output will have no idea what the numbers or identifiers
114
mean. You can add a comment on the test-row that mentions the bug-tracking
115
identifier, when relevant. It's best to avoid spacing characters and
116
characters that may be significant to command-line shells on which you may
117
want to run tests. This makes it easier to specify the test and tag on \l{Qt
118
Test Command Line Arguments}{the command-line} to your test program - for
119
example, to limit a test run to just one test-case.
120
121
\section2 Write Self-contained Test Functions
122
123
Within a test program, test functions should be independent of each other
124
and they should not rely upon previous test functions having been run. You
125
can check this by running the test function on its own with \c {tst_foo
126
testname}. For data-driven tests, likewise, avoid dependencies between the
127
rows of the test's data table so that \c {tst_foo function:tag} can be used
128
to run a single row in isolation (for example, to investigate why it fails).
129
130
Do not re-use instances of the class under test in several tests. Test
131
instances (for example widgets) should not be member variables of the
132
tests, but preferably be instantiated on the stack to ensure proper
133
cleanup even if a test fails, so that tests do not interfere with
134
each other.
135
136
If your test involves making global changes, take care to ensure the prior
137
state is restored at the end of the test, whether it passes or fails. Since
138
failure prevents code later than the failing check from running, restoring
139
at the end of the test doesn't work when the test fails. The robust way to
140
restore even on failure is to instantiate an RAII (resource acquisition is
141
initialization) object whose destructor restores the prior state. This can
142
often be conveniently done using \l qScopeGuard(), for example
143
144
\snippet code/src_qtestlib_qtestcase.cpp 36
145
146
before the first call to \l QLocale::setDefault() in a test that needs to
147
control the locale used by the code under test.
148
149
\section2 Avoid external dependencies
150
151
Test functions should likewise avoid any reliance on external resources.
152
Such a dependency is apt to make the test fail if that resource is
153
transiently unavailable. Even when it is available, the resource may block
154
access by the test system - for example, when tests are run frequently, the
155
resource may interpret the test as an unwelcome burden on its service.
156
157
Skipping the test when inaccessible could hide a problem that would have
158
been revealed had the test been run, making it a poor remedy for these
159
issues. It is better to construct a local mimic of the resource, with enough
160
of its characteristics for the purposes of the test.
161
162
External dependencies also present problems for developers working offline,
163
as well as for testing within a sandbox, such as an isolated virtual
164
machine, when evaluating code changes from untrusted sources. See \l {Qt
165
Test Security Considerations} for related concerns.
166
167
\section2 Test the Full Stack
168
169
If an API is implemented in terms of pluggable or platform-specific backends
170
that do the heavy-lifting, make sure to write tests that cover the
171
code-paths all the way down into the backends. Testing the upper layer API
172
parts using a mock backend is a nice way to isolate errors in the API layer
173
from the backends, but it is complementary to tests that run the actual
174
implementation with data that faithfully illustrates real-world conditions.
175
176
\section2 Make Tests Complete Quickly
177
178
Tests should not waste time by being unnecessarily repetitious, by using
179
inappropriately large volumes of test data, or by introducing needless
180
idle time.
181
182
This is particularly true for unit testing, where every second of extra
183
unit test execution time makes CI testing of a branch across multiple
184
targets take longer. Remember that unit testing is separate from load and
185
reliability testing, where larger volumes of test data and longer test
186
runs are expected.
187
188
Benchmark tests, which typically execute the same test multiple times,
189
should be located in a separate \c tests/benchmarks directory and they
190
should not be mixed with functional unit tests.
191
192
\section2 Use Data-driven Testing
193
194
\l{Chapter 2: Data Driven Testing}{Data-driven tests} make it easier to add
195
new tests for boundary conditions found in later bug reports.
196
197
Using a data-driven test rather than testing several items in sequence in
198
a test saves repetition of very similar code and ensures later cases are
199
tested even when earlier ones fail. It also encourages systematic and
200
uniform testing, because the same tests are applied to each data sample.
201
202
When a test is data-driven, you can specify its data-tag along with the
203
test-function name, as \c{function:tag}, on the command-line of the test to
204
run the test on just one specific test-case, rather than all test-cases of
205
the function. This can be used for either a global data tag or a local tag,
206
identifying a row from the function's own data; you can even combine them as
207
\c{function:global:local}.
208
209
\section2 Use Coverage Tools
210
211
Use a coverage tool such as \l {Coco} or \l {gcov}
212
to help write tests that cover as many statements, branches, and conditions
213
as possible in the function or class being tested. The earlier this is done
214
in the development cycle for a new feature, the easier it will be to catch
215
regressions later when the code is refactored.
216
217
\section2 Select Appropriate Mechanisms to Exclude Tests
218
219
It is important to select the appropriate mechanism to exclude inapplicable
220
tests.
221
222
Use \l QSKIP() to handle cases where a whole test function is found at
223
run-time to be inapplicable in the current test environment. When just a
224
part of a test function is to be skipped, a conditional statement can be
225
used, optionally with a \c qDebug() call to report the reason for skipping
226
the inapplicable part.
227
228
When there are known test failures that should eventually be fixed,
229
\l QEXPECT_FAIL is recommended, as it supports running the rest of the
230
test, when possible. It also verifies that the issue still exists, and
231
lets the code's maintainer know if they unwittingly fix it, a benefit
232
which is gained even when using the \l {QTest::}{Abort} flag.
233
234
Test functions or data rows of a data-driven test can be limited to
235
particular platforms, or to particular features being enabled using
236
\c{#if}. However, beware of \l moc limitations when using \c{#if} to
237
skip test functions. The \c moc preprocessor does not have access to
238
all the \c builtin macros of the compiler that are often used for
239
feature detection of the compiler. Therefore, \c moc might get a different
240
result for a preprocessor condition from that seen by the rest of your
241
code. This may result in \c moc generating meta-data for a test slot that
242
the actual compiler skips, or omitting the meta-data for a test slot that
243
is actually compiled into the class. In the first case, the test will
244
attempt to run a slot that is not implemented. In the second case, the
245
test will not attempt to run a test slot even though it should.
246
247
If an entire test program is inapplicable for a specific platform or unless
248
a particular feature is enabled, the best approach is to use the parent
249
directory's build configuration to avoid building the test. For example, if
250
the \c tests/auto/gui/someclass test is not valid for \macos, wrap its
251
inclusion as a subdirectory in \c{tests/auto/gui/CMakeLists.txt} in a
252
platform check:
253
254
\badcode
255
if(NOT APPLE)
256
add_subdirectory(someclass)
257
endif
258
\endcode
259
260
or, if using \c qmake, add the following line to \c tests/auto/gui.pro:
261
262
\badcode
263
mac*: SUBDIRS -= someclass
264
\endcode
265
266
See also \l {Chapter 6: Skipping Tests with QSKIP}
267
{Skipping Tests with QSKIP}.
268
269
\section2 Avoid Q_ASSERT
270
271
The \l Q_ASSERT macro causes a program to abort whenever the asserted
272
condition is \c false, but only if the software was built in debug mode.
273
In both release and debug-and-release builds, \c Q_ASSERT does nothing.
274
275
\c Q_ASSERT should be avoided because it makes tests behave differently
276
depending on whether a debug build is being tested, and because it causes
277
a test to abort immediately, skipping all remaining test functions and
278
returning incomplete or malformed test results.
279
280
It also skips any tear-down or tidy-up that was supposed to happen at the
281
end of the test, and might therefore leave the workspace in an untidy state,
282
which might cause complications for further tests.
283
284
Instead of \c Q_ASSERT, the \l QCOMPARE() or \l QVERIFY() macro variants
285
should be used. They cause the current test to report a failure and
286
terminate, but allow the remaining test functions to be executed and the
287
entire test program to terminate normally. \l QVERIFY2() even allows a
288
descriptive error message to be recorded in the test log.
289
290
\section1 Writing Reliable Tests
291
292
The following sections provide guidelines for writing reliable tests:
293
294
\list
295
\li \l {Avoid Side-effects in Verification Steps}
296
\li \l {Avoid Fixed Timeouts}
297
\li \l {Beware of Timing-dependent Behavior}
298
\li \l {Avoid Bitmap Capture and Comparison}
299
\endlist
300
301
\section2 Avoid Side-effects in Verification Steps
302
303
When performing verification steps in an autotest using \l QCOMPARE(),
304
\l QVERIFY(), and so on, side-effects should be avoided. Side-effects
305
in verification steps can make a test difficult to understand. Also,
306
they can easily break a test in ways that are difficult to diagnose
307
when the test is changed to use \l QTRY_VERIFY(), \l QTRY_COMPARE() or
308
\l QBENCHMARK. These can execute the passed expression repeatedly, thus
309
repeating any side-effects.
310
311
When side-effects are unavoidable, ensure that the prior state is restored
312
at the end of the test function, even if the test fails. This commonly
313
requires use of an RAII class (see \l {Write Self-contained Test Functions}
314
above), or a \c cleanup() method. Do not simply put the restoration code at
315
the end of the test. If part of the test fails, such code will be skipped
316
and the prior state will not be restored.
317
318
\section2 Avoid Fixed Timeouts
319
320
Avoid using hard-coded timeouts, such as QTest::qWait() to wait for some
321
conditions to become true. Consider using the \l QSignalSpy class,
322
the \l QTRY_VERIFY() or \l QTRY_COMPARE() macros, or the \c QSignalSpy
323
class in conjunction with the \c QTRY_ macro variants.
324
325
The \c qWait() function can be used to set a delay for a fixed period
326
between performing some action and waiting for some asynchronous behavior
327
triggered by that action to be completed. For example, changing the state
328
of a widget and then waiting for the widget to be repainted. However,
329
such timeouts often cause failures when a test written on a workstation is
330
executed on a device, where the expected behavior might take longer to
331
complete. Increasing the fixed timeout to a value several times larger
332
than needed on the slowest test platform is not a good solution, because
333
it slows down the test run on all platforms, particularly for table-driven
334
tests.
335
336
If the code under test issues Qt signals on completion of the asynchronous
337
behavior, a better approach is to use the \l QSignalSpy class to notify
338
the test function that the verification step can now be performed.
339
340
If there are no Qt signals, use the \c QTRY_COMPARE() and \c QTRY_VERIFY()
341
macros, which periodically test a specified condition until it becomes true
342
or some maximum timeout is reached. These macros prevent the test from
343
taking longer than necessary, while avoiding breakages when tests are
344
developed on faster systems and later executed on slower ones.
345
346
If there are no Qt signals, and you are writing the test as part of
347
developing a new API, consider whether the API could benefit from the
348
addition of a signal that reports the completion of the asynchronous
349
behavior. If it would make your testing easier, it may well be useful for
350
callers of your API, too.
351
352
\section2 Beware of Timing-dependent Behavior
353
354
Some test strategies are vulnerable to timing-dependent behavior of certain
355
classes, which can lead to tests that fail only on certain platforms or that
356
do not return consistent results.
357
358
One example of this is text-entry widgets, which often have a blinking
359
cursor that can make comparisons of captured bitmaps succeed or fail
360
depending on the state of the cursor when the bitmap is captured. This,
361
in turn, may depend on the speed of the machine executing the test.
362
363
When testing classes that change their state based on timer events, the
364
timer-based behavior needs to be taken into account when performing
365
verification steps. Due to the variety of timing-dependent behavior, there
366
is no single generic solution to this testing problem.
367
368
For text-entry widgets, potential solutions include disabling the cursor
369
blinking behavior (if the API provides that feature), waiting for the
370
cursor to be in a known state before capturing a bitmap (for example, by
371
subscribing to an appropriate signal if the API provides one), or
372
excluding the area containing the cursor from the bitmap comparison.
373
374
\section2 Avoid Bitmap Capture and Comparison
375
376
While verifying test results by capturing and comparing bitmaps is sometimes
377
necessary, it can be quite fragile and labor-intensive.
378
379
For example, a particular widget may have different appearance on different
380
platforms or with different widget styles, so reference bitmaps may need to
381
be created multiple times and then maintained in the future as Qt's set of
382
supported platforms evolves. Making changes that affect the bitmap thus
383
means having to recreate the expected bitmaps on each supported platform,
384
which would require access to each platform.
385
386
Bitmap comparisons can also be influenced by factors such as the test
387
machine's screen resolution, bit depth, active theme, color scheme,
388
widget style, active locale (currency symbols, text direction, and so
389
on), font size, transparency effects, and choice of window manager.
390
391
Where possible, use programmatic means, such as verifying properties of
392
objects and variables, instead of capturing and comparing bitmaps.
393
394
\section1 Improving Test Output
395
396
The following sections provide guidelines for producing readable and
397
helpful test output:
398
399
\list
400
\li \l {Test for Warnings}
401
\li \l {Avoid Printing Debug Messages from Autotests}
402
\li \l {Write Well-structured Diagnostic Code}
403
\endlist
404
405
\section2 Test for Warnings
406
407
Just as when building your software, if test output is cluttered with
408
warnings you will find it harder to notice a warning that really is a clue
409
to the emergence of a bug. It is thus prudent to regularly check your test
410
logs for warnings, and other extraneous output, and investigate the
411
causes. When they are signs of a bug, you can make warnings trigger test
412
failure.
413
414
When the code under test \e should produce messages, such as warnings
415
about misguided use, it is also important to test that it \e does produce
416
them when so used. You can test for expected messages from the code under
417
test, produced by \l qWarning(), \l qDebug(), \l qInfo() and friends,
418
using \l QTest::ignoreMessage(). This will verify that the message is
419
produced and filter it out of the output of the test run. If the message
420
is not produced, the test will fail.
421
422
If an expected message is only output when Qt is built in debug mode, use
423
\l QLibraryInfo::isDebugBuild() to determine whether the Qt libraries were
424
built in debug mode. Using \c{#ifdef QT_DEBUG} is not enough, as it will
425
only tell you whether \e{the test} was built in debug mode, and that does
426
not guarantee that the \e{Qt libraries} were also built in debug mode.
427
428
Your tests can verify that they do not trigger calls to \l qWarning() by
429
calling \l QTest::failOnWarning(). With no parameter (since Qt 6.8), this
430
makes the test fail if a warning is produced, outputting the warning. You
431
can optionally pass \c failOnWarning() either a warning message to test for
432
or a \l QRegularExpression to match against, so as to limit this behavior to
433
matching warnings. (These filtered version were introduced in Qt 6.3.)
434
435
You can also set the environment variable \c QT_FATAL_WARNINGS to cause
436
warnings to be treated as fatal errors. See \l qWarning() for details; this
437
is not specific to autotests. If warnings would otherwise be lost in vast
438
test logs, the occasional run with this environment variable set can help
439
you to find and eliminate any that do arise.
440
441
\section2 Avoid Printing Debug Messages from Autotests
442
443
Autotests that pass should not produce any unhandled warning or debug
444
messages. This will allow the CI Gate to treat new warning or debug messages
445
as test failures. As with warnings from compilers when building your code,
446
if warnings are rare they are useful clues to problems, but if they are
447
routine they may hide meaningful issues from developers testing their
448
changes.
449
450
Adding debug messages during development is fine, but these should be
451
either disabled or removed before a test is checked in.
452
453
\section2 Write Well-structured Diagnostic Code
454
455
Any diagnostic output that would be useful if a test fails should be part
456
of the regular test output rather than being commented-out, disabled by
457
preprocessor directives, or enabled only in debug builds. If a test fails
458
during continuous integration, having all of the relevant diagnostic output
459
in the CI logs could save you a lot of time compared to enabling the
460
diagnostic code and testing again. Epecially, if the failure was on a
461
platform that you don't have on your desktop.
462
463
Diagnostic messages in tests should use Qt's output mechanisms, such as
464
\c qDebug() and \c qWarning(), rather than \c stdio.h or \c iostream.h output
465
mechanisms. The latter bypass Qt's message handling and prevent the
466
\c -silent command-line option from suppressing the diagnostic messages.
467
This could result in important failure messages being hidden in a large
468
volume of debugging output.
469
470
Where there is a need, on failure, to augment the output of the Qt Test
471
macros such as \l QCOMPARE(), one useful pattern is to have the diagnostic
472
code run by a \l qScopeGuard() instantiated before, and then
473
\l {QScopeGuard::} {dismiss()} the instance after, the check or checks whose
474
failure would be easier to understand with that output. The diagnostic code
475
is then only run when a check, by failing, skips the later \c dismiss()
476
call. For example:
477
478
\snippet code/src_qtestlib_qtestcase.cpp scope-diagnostic
479
480
This augments the \c QCOMPARE() output on failure with a helpfully-formatted
481
representation of the \c actual result, to make it easier to compare it with
482
a test-case's \c expected result (already available in the test's own source
483
code). Other situations may need more complex diagnostics.
484
485
\section1 Writing Testable Code
486
487
The following sections provide guidelines for writing code that is easy to
488
test:
489
490
\list
491
\li \l {Break Dependencies}
492
\li \l {Compile All Classes into Libraries}
493
\endlist
494
495
\section2 Break Dependencies
496
497
The idea of unit testing is to use every class in isolation. Since many
498
classes instantiate other classes, it is not possible to instantiate one
499
class separately. Therefore, you should use a technique called
500
\e {dependency injection} that separates object creation from object use.
501
A factory is responsible for building object trees. Other objects manipulate
502
these objects through abstract interfaces.
503
504
This technique works well for data-driven applications. For GUI
505
applications, this approach can be difficult as objects are frequently
506
created and destructed. To verify the correct behavior of classes that
507
depend on abstract interfaces, \e mocking can be used. For example, see
508
\l {Googletest Mocking (gMock) Framework}.
509
510
\section2 Compile All Classes into Libraries
511
512
In small to medium sized projects, a build script typically lists all
513
source files and then compiles the executable in one go. This means that
514
the build scripts for the tests must list the needed source files again.
515
516
It is easier to list the source files and the headers only once in a
517
script to build a static library. Then the \c main() function will be
518
linked against the static library to build the executable and the tests
519
will be linked against the static libraries.
520
521
For projects where the same source files are used in building several
522
programs, it may be more appropriate to build the shared classes into
523
a dynamically-linked (or shared object) library that each program,
524
including the test programs, can load at run-time. Again, having the
525
compiled code in a library helps to avoid duplication in the description
526
of which components to combine to make the various programs.
527
528
\section1 Setting up Test Machines
529
530
The following sections discuss common problems caused by test machine setup:
531
532
\list
533
\li \l {Screen Savers}
534
\li \l {System Dialogs}
535
\li \l {Display Usage}
536
\li \l {Window Managers}
537
\endlist
538
539
All of these problems can typically be solved by the judicious use of
540
virtualisation.
541
542
\section2 Screen Savers
543
544
Screen savers can interfere with some of the tests for GUI classes, causing
545
unreliable test results. Screen savers should be disabled to ensure that
546
test results are consistent and reliable.
547
548
\section2 System Dialogs
549
550
Dialogs displayed unexpectedly by the operating system or other running
551
applications can steal input focus from widgets involved in an autotest,
552
causing unreproducible failures.
553
554
Examples of typical problems include online update notification dialogs
555
on \macos, false alarms from virus scanners, scheduled tasks such as virus
556
signature updates, software updates pushed out to workstations, and chat
557
programs popping up windows on top of the stack.
558
559
\section2 Display Usage
560
561
Some tests use the test machine's display, mouse, and keyboard, and can
562
thus fail if the machine is being used for something else at the same
563
time or if multiple tests are run in parallel.
564
565
The CI system uses dedicated test machines to avoid this problem, but if
566
you don't have a dedicated test machine, you may be able to solve this
567
problem by running the tests on a second display.
568
569
On Unix, one can also run the tests on a nested or virtual X-server, such as
570
Xephyr. For example, to run the entire set of tests on Xephyr, execute the
571
following commands:
572
573
\code
574
Xephyr :1 -ac -screen 1920x1200 >/dev/null 2>&1 &
575
sleep 5
576
DISPLAY=:1 icewm >/dev/null 2>&1 &
577
cd tests/auto
578
make
579
DISPLAY=:1 make -k -j1 check
580
\endcode
581
582
Users of NVIDIA binary drivers should note that Xephyr might not be able to
583
provide GLX extensions. Forcing Mesa libGL might help:
584
585
\code
586
export LD_PRELOAD=/usr/lib/mesa-diverted/x86_64-linux-gnu/libGL.so.1
587
\endcode
588
589
However, when tests are run on Xephyr and the real X-server with different
590
libGL versions, the QML disk cache can make the tests crash. To avoid this,
591
use \c QML_DISABLE_DISK_CACHE=1.
592
593
Alternatively, use the offscreen plugin:
594
595
\code
596
TESTARGS="-platform offscreen" make check -k -j1
597
\endcode
598
599
\section2 Window Managers
600
601
On Unix, at least two autotests (\c tst_examples and \c tst_gestures)
602
require a window manager to be running. Therefore, if running these
603
tests under a nested X-server, you must also run a window manager
604
in that X-server.
605
606
Your window manager must be configured to position all windows on the
607
display automatically. Some windows managers, such as Tab Window Manager
608
(twm), have a mode for manually positioning new windows, and this prevents
609
the test suite from running without user interaction.
610
611
\note Tab Window Manager is not suitable for running the full suite of
612
Qt autotests, as the \c tst_gestures autotest causes it to forget its
613
configuration and revert to manual window placement.
614
*/
qtbase
src
testlib
doc
src
qttest-best-practices.qdoc
Generated on
for Qt by
1.16.1