Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Test your changes

This page covers the automated tests, the fake backends for the desktop side, and the rules for tests on a real phone. First set up a development environment.

Run the Rust tests

  1. Run every test of the workspace, as CI does:

    cd desktop
    cargo test --workspace
    
  2. Run them again with the GTK app’s fake daemon compiled in. This adds the tests of the mock itself, which CI does not run:

    cargo test --workspace --features tether-gtk/mock
    
  3. Run the two checks that CI runs before the tests:

    cargo fmt --all --check
    cargo clippy --workspace --all-targets -- -D warnings
    

To run the tests of one crate, name it: cargo test -p tether-core. Unit tests are next to the code. The integration tests of tether-core are in desktop/crates/tether-core/tests/. They start two cores in one process and run pairing, the QR flow, disconnect and hold, messages, calls, streams and the enhanced tier messages between them.

Tests that decode video or play audio skip an element that is not installed and print skipping: GStreamer element … is not installed.

Run the Android unit tests

cd android
./gradlew :app:testDebugUnitTest

These are JVM tests that need no phone and no emulator. They cover framing, the pairing code and QR vectors, stream handling, feature logic and the pure parts of the shell helper (org.tether.shell). The HTML report is in android/app/build/reports/tests/.

There are no instrumented tests. Behaviour on a real phone is checked by hand with the checklists.

Know what CI runs

A pull request must pass these jobs. Each runs only when its part of the repository changed.

WorkflowRuns when these changeCommands
Desktopdesktop/, proto/cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace
Androidandroid/, proto/./gradlew --no-daemon --stacktrace :app:testDebugUnitTest :app:assembleDebug
Docsdocs/, book.toml, CHANGELOG.mdpython3 docs/tools/check_links.py, mdbook build
  • The Desktop job runs on Ubuntu 24.04 with the latest stable Rust and with RUSTFLAGS=-D warnings, so a compiler warning fails the build, also in cargo test.

  • The Desktop job uses the default features. It does not build or test the mock feature of tether-gtk. When you touch the GTK app, run these yourself:

    cargo clippy --workspace --all-targets --features tether-gtk/mock -- -D warnings
    cargo test --workspace --features tether-gtk/mock
    
  • The Android job uses JDK 21, platform 35 and build tools 35.0.0.

On a v* tag the workflows also build the .deb and the signed APK. See Package and release.

Keep the shared test vectors green

The Rust and the Kotlin implementation must compute the same bytes. The wire protocol reference contains test vectors for the pairing code, the QR proof and the first frame of a secondary stream (sections “Test vectors” and “Test vectors (M2)”). Both sides have unit tests that check those values:

SideTests
Rustdesktop/crates/tether-core/src/pairing.rs (sas_vector_1, sas_vector_2, qr_proof_vector), desktop/crates/tether-core/src/streams.rs (stream_open_test_vector)
Kotlinandroid/app/src/test/java/org/tether/android/pairing/SasTest.kt, QrPairingUriTest.kt, android/app/src/test/java/org/tether/android/transport/StreamManagerTest.kt

If you change pairing or framing, change the vector in the reference and the tests on both sides in the same pull request. See Add or change a protocol feature.

Test the user interface with the mock backend

The GTK app built with the feature mock contains a fake daemon. Use it for all work on the user interface.

  1. Start it with scratch directories, so that it does not write to the settings of your installed app:

    cd desktop
    XDG_CONFIG_HOME=/tmp/tether-mock/config XDG_DATA_HOME=/tmp/tether-mock/data \
      cargo run -p tether-gtk --features mock -- --mock
    
  2. Wait for the scripted events, or set the state you need with an environment variable in front of the command:

    VariableEffect
    TETHER_MOCK_QUIET=1No scripted pair request and reply requests, which open dialogs and switch tabs
    TETHER_MOCK_FIRST_CALL=<seconds>When the first fake incoming call arrives
    TETHER_MOCK_BT=off|unavailable|unpaired|paired|connectedInitial Bluetooth state
    TETHER_MOCK_ENHANCED=<state>Initial state of the enhanced tier. not_set_up shows the set-up wizard path
    TETHER_MOCK_ADB=missing|too_oldState of adb on the computer
    TETHER_MOCK_APPS=empty|errorApps tab without apps, or with an error
    TETHER_MOCK_AUDIO=unsupported|error|playback|playback_dupPhone audio state
    TETHER_MOCK_WEBCAM_SETUP=not_installed|not_loaded|no_device|ready|unsupportedState of the virtual camera

    The complete list, the timing of every scripted event and the texts that make an action fail are in the tether-gtk README.

  3. To open only the mock phone’s screen window:

    cargo run -p tether-gtk --features mock -- --mock --mirror 5b7a
    
  4. To see every event the fake daemon emits and every input record the fake screen receives, add RUST_LOG=tether=debug.

The mock phone pushes a clipboard text about 45 seconds after the start, and the app puts it on your desktop clipboard.

The window must stay usable down to a width of 360 px. Check narrow widths when you change a layout.

Test the daemon with the fake phone

fake_phone is an example program in tether-core that speaks the phone’s side of the protocol: pairing, battery, notifications, messages, contacts, media, volumes, do-not-disturb, connectivity, clipboard, files, photos, calls, the call log and a short app list. It has no adb side. For screen mirroring, app windows, phone audio and the webcam, use the mock backend or a real phone.

  1. Start a daemon. To keep it apart from an installed one, start it as described in “Run a debug daemon beside the installed one” in Build, run and install from source, with TETHER_PEER_PORT set to the fake phone’s port. The tutorial shows the complete commands.

  2. Start the fake phone and let it dial the daemon:

    cargo run -p tether-core --example fake_phone -- \
      --port 7363 --dial 127.0.0.1:7362 --no-beacon --no-mdns
    
  3. Pair with tether-cli pair <id> and drive the daemon with tether-cli or over D-Bus.

OptionEffect
--port <n>Port the fake phone listens on (default 7361)
--name <text>Name it announces (default “Fake Phone”)
--dial <host:port>Dial a daemon instead of waiting to be discovered
--data <dir>Where it keeps its identity and trusted devices (default tether-fake-phone in the temporary directory). Keep the directory to stay paired between runs
--no-beacon, --no-mdnsDo not announce itself by UDP beacon or by mDNS. Without them the fake phone announces itself on the network on the standard port 7360, and an installed daemon lists it as a device
--manualAsk before confirming the pairing code instead of confirming at once
--initiateRequest pairing from the phone’s side when it connects unpaired
--no-cap <capability>Leave one capability out of its Hello. Repeat for more. Tests capability gating.
--m1Announce only the Milestone 1 capabilities
--period <seconds>Interval of the battery and notification updates (default 20)
--share-file <path>Offer this file to the desktop after pairing. Repeat for more
--call-in <seconds>Ring with an incoming call that long after every connect

While paired, a clipboard text sent with tether-cli clipboard <id> send <word> triggers a hook in the fake phone: share offers the --share-file files again, url and text share a link or a text, clip sends a clipboard text back, call rings now, hangup makes the caller hang up.

Test the shell helper with helper_test.py

android/tools/helper_test.py starts the enhanced tier’s shell helper on a phone connected over adb and talks to it directly, without the daemon. It needs only Python 3. The installed Android app provides the helper. --classpath <path> runs it from an APK that you pushed to the phone.

python3 android/tools/helper_test.py --help
ModeWhat it does on the phoneWhat it writes on the computer
no mode option (default)Handshake, grant check, writes test strings to the clipboard, mirrors the phone’s main display, sends Home and a tap, turns the screen off and onThe main display’s video, as mirror.h264 (--out)
--app <package>Opens that app on a new virtual display, types, taps, resizesThe video of that virtual display only
--audioCaptures each audio source for --seconds. --play <command> runs a command on the phone once the capture runsWhatever the phone plays, as one .opus file (Ogg) per source
--cameraLists the cameras and captures for --seconds, counting packets and bytesNothing

Warning

Do not run the default mode on a phone that is in daily use. It records the phone’s main display, with whatever is on it, to mirror.h264. No option stops that recording: --no-clipboard, --no-input and --no-screen-off switch off only the clipboard, input and screen-off parts.

The clipboard part writes test strings and never requests the existing clipboard content, but it leaves the clipboard overwritten.

Test against a real phone

A test phone is often somebody’s daily phone, with their messages, photos and accounts on it. Automated tests on such a phone have captured private content before (see the session notes). These rules apply to every test that a person or a program runs against a phone that is in use.

  • Screen: never capture, dump or screenshot the phone’s main display. Use only a display that the test itself created. Before you rely on a tool’s display argument, check on a harmless screen that the tool honours it: uiautomator dump --display-id ignores it on One UI 8.5 and dumps the main screen.
  • Audio: capture audio only while nothing is playing, or with a test tone that the test itself starts.
  • Clipboard: never read the clipboard. Write a test string and read that back.
  • Camera: count frames and statistics only. Never save or view camera frames, and check that the test releases the camera when it ends.
  • Before a test run, tell the phone’s owner what will be visible or audible on the phone. Afterwards, report what was touched: apps opened, settings changed, the clipboard.
  • Prefer a spare phone or an emulator for anything that reads content.
  • Apps opened on virtual displays show up in the phone’s Recents, and a list of the installed apps is personal data too. Do not paste either into an issue or a pull request.
  • Remove test artefacts from the phone and from your computer when you are done.
  • Remove names, numbers and message texts from logs before you attach them to an issue.

When an AI coding agent runs device tests for you, give it these rules as part of the task.

Run the manual checklists

Features that depend on a real phone, a real call or a real Bluetooth link are verified by hand. Each checklist is a table of numbered steps with the expected result.

Run the sections that your change touches, on your own phone. Say in the pull request which rows you ran, on which phone model, Android version and desktop session. Rows that nobody has verified yet are listed in the status sections of the roadmap.