Testing
Test QML applications with tst_*.qml files and ljos test, render
deterministic pictures with ljos render, and write Gherkin
behaviour scenarios.
This page shows you how to run
tst_*.qml test suites with ljos test, capture deterministic headless screenshots with ljos render, and write Gherkin behaviour scenarios for your application.Files named
tst_*.qml that use import QtTest and TestCase run unchanged on Ljós. ljos test executes them headlessly on a virtual clock and prints the output in qmltestrunner's text format.Create a file named
tst_click.qml:Run
ljos test in the directory (or pass specific files or directories):Inside a
TestCase function you can use:Assertions:
compare(actual, expected), verify(condition, message), fuzzyCompare(actual, expected, delta), tryCompare(obj, property, expected, timeout), tryVerify(function, timeout) and fail(message).Signals:
SignalSpy to count signal emissions and inspect signal arguments.Input synthesis:
mouseClick, mousePress, mouseRelease, mouseMove, keyClick, keyPress, keyRelease and TouchEventSequence. Input events travel through the same hit-testing and focus paths as real user input, so clicking a MouseArea with no coordinates clicks its centre (width / 2, height / 2).Time:
wait(ms) and waitForRendering(item) advance the virtual clock without sleeping in real wall-clock time.Use
--filter to run a single case, function or data tag, --import to add module search paths, and --json to save a machine-readable report:The exit status of
ljos test is the number of failed tests (or 0 when all pass).When you want to verify how a component looks or capture a reference image in CI without a display server, use
ljos render:ljos render is deterministic by default:Virtual clock:
--settle <MS> (default 1500) advances the virtual clock so timers and entry animations reach their target state before the frame is drawn.Pinned wall clock:
--now <RFC3339> (for example, --now 2026-03-30T14:00:00Z) pins the timestamp seen by JavaScript Date at start-up and advances it by --settle.Bundled font: Unless you pass
--system-fonts, Ljós renders text using only its bundled font so glyphs match across Linux, macOS and CI runners.Offline by default: Network fetches fail immediately unless you pass
--network.In addition to
tst_*.qml, Ljós uses Gherkin .feature files (run with cucumber through crates/ljos_bdd) to specify user-visible application behaviour.Behaviour steps never refer to internal rendering types. Instead, they interact with your QML scene the same way a person using a screen reader or a coding agent does:
Interactive controls are addressed by role and accessible name (such as
When the user clicks the "button" "Save"). Clicking a control moves the pointer to the centre of the control and dispatches the click through the input router; disabled controls and items hidden behind disabled parents are not clicked.Objects and properties are read or written by
objectName path (such as Then the property "saved" of "root" is 1).Time advances on the virtual clock with steps such as
When 500 milliseconds pass.Here is a complete example from the test suite:
In the Ljós workspace, run scenarios with
mise:Set
LJOS_SHOTS=<dir> when running scenarios to save a rendered PNG after every step, which makes diagnosing a failing step straightforward.If you are migrating an existing application that already has its own Gherkin suite, you can run its UI scenarios against Ljós without modifying the suite's
.feature files. An acceptance directory under acceptance/<suite>/ holds:PIN: the application repository and commit hash;features.globs: an allowlist of .feature files or file.feature:ScenarioName* globs;RATCHET: the list of scenario IDs that currently pass;a small
steps adapter crate that maps the application's UI steps (find, click, key, touch, property reads) to Ljós's Backend trait.Run the suite against its ratchet with:
Passing
--raise adds newly passing scenarios to RATCHET and never removes existing ones.