JFLib
EN
cargo jflib test

Tests that read like instructions.

A .uis script uses your app the way a person does. It clicks, types, drags, swipes and presses keys, then checks what happened. It runs the real app without a window, on a virtual clock, so every run ends with the same result and the same pixels, on your machine and in CI.

One line, one step.

This script fills in part of the Feature Gallery. Each picture is what the app looked like right after that line. Lines that start with expect are the checks. Click a line to jump there.

The text field Enter a name has the focus. The text field now holds Ada Lovelace. The check box Option A is cleared. The radio button Blue is chosen. The slider is dragged to 84 percent. Tab moved the focus to the vertical slider, and two presses of the up key raised it. The same form in dark mode.
  1. click #700
  2. type "Ada Lovelace"
  3. expect #700 text "Ada Lovelace"
  4. click "Option A"
  5. expect checkbox:"Option A" unchecked
  6. click "Blue"
  7. expect radio:"Blue" checked
  8. drag 105,446 186,446 12
  9. expect #140 value 84
  10. key tab up up
  11. expect #141 focused
  12. expect #141 value 14
  13. theme dark

Why it works so well.

The real app

No mocks and no test build. The script feeds the compiled app the same events the platform would.

Headless

The app draws into memory. No window opens, nothing steals your keyboard, and a server without a desktop runs it too.

Deterministic

Time is a virtual clock in 16 ms frames. Timers and animations follow it, so a run never waits and never flakes.

Readable selectors

Name a widget by its label, by kind and label, by id or by a point. Clear rules decide when a label appears twice.

Clear failures

FAIL line 9: … names the line and what was found instead. The script goes on, and the exit code tells CI.

One language everywhere

The same scripts run on Windows and Linux, and they drive the inspector too.

Everything a person can do.

And a few things a person cannot: a script can drop files from another program, suspend the app, feed it sensor readings or lose the GPU, all without a real device.

Mouse and keyboardButtons, modifiers, wheel zoom and key chords, each key in a frame of its own, as the platform delivers them.
rclick listitem:"report.pdf"
click "Rename"
type "final.pdf\n"
drag #20 #31 hold 300 shift
wheel 400,300 120 ctrl
key ctrl+s
Touch and penFingers with real speeds, two-finger gestures and pen pressure.
tap "Photos"
longpress #44 800
swipe 200,600 200,150 250
pinch 300,300 80 240
pan2 300,300 0 -120
drag 100,100 300,180 pen 20 90
Windows and dialogsTool windows, dialogs and popups, each with its own state.
click "Save as…"
expect dialog:"Save as" open
window any
click button:"Cancel"
expect window 20 closed
shot popups.png desktop
Drag and dropFiles, text, HTML, URLs and images from other programs, and what your app hands out.
drop 300,200 photo.png notes.txt
dragover 300,200 text
dragleave
drag #12 1200,300
dragout expect files 1
dragout end copy
ClipboardA clipboard of its own for every run. Your real one is never touched.
clip text "Hello"
key ctrl+v
expect #700 text "Hello"
key ctrl+a ctrl+c
clip expect text
The system around the appLifecycle, settings, sensors and location, as the host would deliver them.
system suspend
system resume
system settings theme
sensor accel 0 9.81 0
location 52.52 13.40 12
location expect fix

Check what matters, down to the pixel.

Expectations read states, values, texts and rectangles from the same records that screen readers and the inspector see. When pixels matter, a script compares a point, an area or the whole window with an earlier picture, byte for byte.

  • States: exists, focused, checked, disabled, selected, open, pressed and more.
  • Values, ranges, texts and rectangles in device-independent pixels.
  • Theme tokens, the style in use, sounds asked for and warnings printed.
  • --verify-dirty compares every partial redraw with a full one, so a missed pixel cannot hide.
expect button:"Send" disabled
type "Hi"
expect button:"Send" enabled
expect #140 value 40..60
expect text:"Saved" exists
expect #9 rect * * * 36
expect pixel 12 40 #0067C0
expect token accent_text #FFFFFF

shot before.png
theme dark
theme light
expect same before.png       # byte for byte

Frame budgets as tests.

bench times real frames while things move: an animation, a drag, a stream of wheel turns. It prints the mean, the median and the worst frame, and with a limit it fails when the median is over budget. Three tries ride out a busy build machine.

JFNetworker's performance test pans, zooms and drags a network of 500 devices and 800 cables at 1920 × 1080 this way.

# 300 frames of a drag, at most 16.6 ms each
bench 300 drag #50 900,500 16600

# smooth scrolling
wheel 500,400 -360
bench 60 anim 16600

Every animation on this site is a script.

The GIFs and screenshots here were not recorded by hand. A script brings each app into the right state and takes a picture after each step, headless. Run it again after a change, and the pictures update themselves.

A panel dragged out of its tab group, over the drop markers, and docked again.

Every new app starts with a passing test.

cargo jflib new writes tests/smoke.uis next to your code. cargo jflib test builds the app and runs every script in tests/. A first line #!args passes program arguments, and dump prints the widget tree with ids and positions when you write a new script.

The inspector shows the selector of any widget you point at, ready to paste.

# tests/smoke.uis
click "Click me"
click "Click me"
expect text:"Clicks: 2" exists
click "Reset"
expect text:"Clicks: 0" exists
shot target/smoke.png