GUIDE / QUALITY AND DELIVERY

Testing your application

Check compilation, click real controls headlessly, and test behavior rather than generated internals.

Core janelkit Included with janelkit. Nothing extra to install.
CHAPTER 26 / 29~5 min read · try examples at your own pace
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

What you will learn

  • Separate compilation checks from startup and behavior tests.
  • Write a repeatable headless test with stable element IDs.
  • Know what the inspector covers and what still needs a manual check.

Compilation and behavior are different checks

A compiler check asks whether a component uses valid syntax, supported elements, and valid references. A behavior test asks whether the application does what a user expects. Both matter. A component may compile and still add the wrong item or forget to clear an input.

Start by running janel build from the application folder. This validates all .janel components, including components not currently used, and writes generated QML. It does not click controls, prove business logic, or package an executable.

janel build does not ask Qt to load the generated view. A misspelled color such as blu can pass compilation and still prevent startup. Add a mount test, then exercise behavior; do not interpret a successful build as a startup guarantee.

shell
janel build
# For a single component diagnostic:
janel parse src/App.janel
janel compile src/App.janel
Copy

How it works

  1. build is the quick project-wide validity check. Fix compile errors before looking for a visual behavior bug.
  2. parse exposes the parsed structure; compile shows generated QML. These are debugging outputs, not files you should edit as application source.

What you should see

A successful build completes without compiler errors and writes output to build/qml by default. That success alone does not mean the application behavior has been tested.

Learn moreCLI and tooling ↗Errors and troubleshooting ↗Style reference ↗

Give a small component an observable behavior

For this example, save the following complete component as src/App.janel in a scaffolded project. The count-label and increment IDs give the test stable ways to find the controls. An ID is a lookup label, not a reactive value.

The requirement is concrete: after one click, the text should be Count: 1. A useful test can describe that outcome without depending on generated QML classes or private runtime attributes.

janel
<script lang="python">
from janelkit import state
count = state(0)

def increment():
    count.value += 1
</script>

<window title="Testable counter" width={420} height={260}>
  <column>
    <text id="count-label">Count: {count}</text>
    <button id="increment" on:click={increment}>Increment</button>
  </column>
</window>
Copy

Complete component · Save as src/App.janel in a scaffolded project.

How it works

  1. The inspector finds the <text> and <button> by their element names whether they are written here, passed through a slot or the root of a child component.
  2. Stable IDs let the test identify a control without depending on the wording of its caption.

What you should see

The window starts at Count: 0. Clicking Increment changes it to Count: 1.

Write your first headless interaction test

Headless means the interface is constructed without showing a visible window. The public janelkit.inspect.mount helper manages this lifetime with a Python with block. Once inside, find selects an element and click drives its real event path. On leaving the block, the application is cleaned up.

Save the following Python file as tests/test_counter.py. Install pytest in your application environment and run python -m pytest from the project root. These are desktop application tests; they do not use the website browser test runner.

python
from janelkit.inspect import mount

def test_increment_updates_label():
    with mount("src/App.janel", headless=True) as app:
        assert app.find("text", id="count-label").text == "Count: 0"
        app.find("button", id="increment").click()
        assert app.find("text", id="count-label").text == "Count: 1"
Copy

How it works

  1. mount locates the component file relative to the test process working directory. Run from the app root, or resolve an absolute path deliberately.
  2. find requires a single visible match. The element type plus ID avoids selecting an unrelated button with similar text.
  3. The first assertion confirms the initial state; the second proves the click changed user-visible output.
  4. The with block disposes the mounted application even when an assertion fails.

What you should see

pytest reports a passing test. If increment stops changing state, the final assertion fails with the old displayed text.

Common mistakes

  • Do not import janelkit.runtime or inspect generated QML to test a public behavior. Those are internal contracts.
  • A test that only checks a Python variable can miss a broken binding between that state and the interface.

Exercise the same controls the user does

The inspector supports more than clicks. type replaces the existing text, submit sends a field submission, check changes a boolean, choose selects an option, slide changes a slider, and key sends keyboard input. find_all is useful when multiple matches are expected. app.texts() collects every visible <text>, including the root of a child component and text passed through a slot. In fields, .text is None: read what was typed with .value, and find a field by placeholder, label or id, because find(text=...) does not match fields. click(x=, y=) clicks a point of the element, and screenshot(path) captures the window or one element.

For async work, app.wait(seconds, until=...) processes the application while waiting for a result. Test success, error, loading, repeated requests, and the component disappearing during work. A timeout should fail the test rather than silently accepting an incomplete operation.

app.wait(seconds) runs the application for that long. app.wait(until=lambda: ..., timeout=2.0) runs it until the condition holds, and fails with InspectError if timeout seconds (5 by default) pass first. Keep assertions inside the with block: Qt items are destroyed when the mount closes.

BehaviorPublic inspection toolWhat to assert
Enter a nameelement.type("Ada")The bound greeting changes
Submit a formfield.submit()The item appears and draft clears
Toggle a choicecheckbox.check(True)State and visible status agree
Choose an optionselect.choose(value)The correct value is displayed
Keyboard shortcutapp.key("Ctrl+Z")The previous edit is restored
Await a taskapp.wait(until=condition)The result or error state appears

Keep tests independent from real user data

Tests must not overwrite personal preferences or make paid service requests accidentally. Each mount starts a new session with an empty temporary data folder, so persisted values and the stores of janelkit-store never touch real data, and a test never sees what the previous one left. If you deliberately test persistence across two mounts, set JANELKIT_DATA_DIR to a directory owned by that test. Do not aim it at real application data.

Move file parsing, validation, and service logic into ordinary Python functions and test those independently. Then keep a smaller set of UI tests to prove the components connect to those functions correctly. Replace external network services at your application service boundary in tests; do not fake a successful framework interaction instead of exercising it.

  1. Write the expected user-visible behavior first.
  2. Run the test and confirm it fails for the missing behavior, not because of a broken import or path.
  3. Implement the smallest component change that satisfies the behavior.
  4. Run that test, the rest of your application tests, and janel build.
  5. Manually review keyboard behavior and the packaged application on each platform you support.

Common mistakes

  • A headless test is not a substitute for checking readability, keyboard focus, and native platform behavior.
  • Canceling a UI task does not stop a synchronous worker or an external provider request; design service tests around that boundary.

What the inspector covers, and what it does not

The inspector finds every element by its element name, also when it is the root of a child component or passed through a slot: a component whose root is a <button> is found as find("button") and as find("Name"), and click() and type() drive it as the control it is. A few things still need care.

SituationWhat to do
An element stops working after the with blockRead and interact with elements before the mount closes: its Qt items are destroyed with it.
A screenshot of a headless mount on Windows has no fonts or videoMount with headless=False to look at a capture; keep assertions on texts and values.
The application opens a native dialogWith janelkit-desktop, answer it with app.answer_dialog(result).
A page of janelkit-router, or a store of janelkit-storeFind a page by its component name; read a store with app.store(Class). Both packages document their test helpers.

Common mistakes

  • Do not replace a failed UI action with a state assignment and report that the interaction passed.
  • Offscreen tests do not verify native dialogs, platform notifications, visual contrast or the distributed executable.

Learn moreComponents ↗Forms and two-way binding ↗Errors and troubleshooting ↗

Key points

  • A successful build is not proof that Qt can load the view or that behavior is correct.
  • Assert visible behavior inside the mount block, using stable IDs.
  • Test ordinary Python separately and review native behavior manually.

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.