Get started
Introduction
Installation
Your first app
Tutorials
Fission tutorials
Test Android app behaviour on the emulator and phone
Core concepts
Components
State and effects
Protected routes
Server-side rendering
Styling
Testing
Deployment
Reference
API reference
Cookbook
Fission 0.16.0
Documentation version
Read the changelog →

Test Android app behaviour on the emulator and phone

Test a lunchbox planner's rules, clipboard effect and native interaction separately. Use manual LiveTest curl requests without shipping a release control server.
Android

What you will build

Check the planner's quantity rules and copy action through focused Rust tests, host startup and a native LiveTest interaction.
Test quantity bounds and reject edits during an in-flight copy
Keep a memory clipboard provider confined to tests
Drive semantic controls with manual curl requests to the native LiveTest /cmd API
Inspect returned command status and screenshots separately from HTTP success and host startup
Different tests answer different questions. A unit test can establish a quantity limit without launching Android. A provider test can check a memory clipboard without proving an OS clipboard works. A native LiveTest can activate the composed button and inspect the result, but that still does not qualify every device permission or lifecycle condition.
Here, the app plans a lunchbox quantity and copies that number for use in an external order. It has one bounded rule, a real asynchronous host action and explicit semantic targets. That gives each test layer something concrete to verify instead of displaying a menu of test commands and calling it an app test.
Start from a new project (optional)

Create the Android project

Complete Android SDK/NDK setup, then prepare an emulator or connect a phone.
cargo install cargo-fission
fission init android-test-android-app-behaviour-on-the-emulator-and-phone
cd android-test-android-app-behaviour-on-the-emulator-and-phone
fission add-target android --project-dir .
cargo add serde_yaml
Clipboard text access is built into the shell. Keep the generated src/main.rs; the shared library below launches this app on Android and exposes test control only in a debug Android build.

Run the finished example

fission run --target android --project-dir .

1. Build the rule and the observable interaction

Quantity belongs to shared state and has one range rule: 1–20. The reducers call that rule, rather than only hiding an invalid action in the view. Copy freezes the quantity whilst the request is pending, so its acknowledgement cannot be mistaken for a later edited plan.
The memory provider appears only inside a Rust test. The runnable native and Web apps use their real default clipboard hosts.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/state.rs","value":"src-state-rs"},{"index":1,"label":"src/app.rs","value":"src-app-rs"},{"index":2,"label":"src/translations.rs","value":"src-translations-rs"},{"index":3,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":4,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"},{"index":5,"label":"src/lib.rs","value":"src-lib-rs"},{"index":6,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/state.rs","value":"src-state-rs"}
use fission::prelude::*;

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum CopyStatus {
    #[default]
    Idle,
    Pending,
    Copied,
    Unsupported,
    Failed,
}
impl CopyStatus {
    pub fn key(self) -> &'static str {
        match self {
            Self::Idle => "lunch.ready",
            Self::Pending => "lunch.copying",
            Self::Copied => "lunch.copied",
            Self::Unsupported => "lunch.unsupported",
            Self::Failed => "lunch.failed",
        }
    }
}

#[derive(Debug)]
pub struct LunchPlanState {
    pub quantity: u16,
    pub copy_status: CopyStatus,
}
impl Default for LunchPlanState {
    fn default() -> Self { Self { quantity: 1, copy_status: CopyStatus::Idle } }
}
impl GlobalState for LunchPlanState {}

impl LunchPlanState {
    pub fn increase(&mut self) {
        if self.copy_status == CopyStatus::Pending { return; }
        self.quantity = self.quantity.saturating_add(1).min(20);
        self.copy_status = CopyStatus::Idle;
    }
    pub fn decrease(&mut self) {
        if self.copy_status == CopyStatus::Pending { return; }
        self.quantity = self.quantity.saturating_sub(1).max(1);
        self.copy_status = CopyStatus::Idle;
    }
}

pub fn copy_quantity(state: &mut LunchPlanState, ctx: &mut ReducerContext<LunchPlanState>) {
    if state.copy_status == CopyStatus::Pending { return; }
    state.copy_status = CopyStatus::Pending;
    let ok = ctx.effects.bind(QuantityCopied, reduce_with!(quantity_copied));
    let err = ctx.effects.bind(CopyFailed, reduce_with!(copy_failed));
    ctx.effects.clipboard().write_text(ClipboardWriteTextRequest {
        text: state.quantity.to_string(),
    }).on_ok(ok).on_err(err);
}

#[fission_reducer(QuantityCopied)]
fn quantity_copied(state: &mut LunchPlanState, ctx: &mut ReducerContext<LunchPlanState>) {
    if state.copy_status != CopyStatus::Pending { return; }
    state.copy_status = if ctx.input.capability_ok(WRITE_CLIPBOARD_TEXT).is_some() {
        CopyStatus::Copied
    } else {
        CopyStatus::Failed
    };
}

#[fission_reducer(CopyFailed)]
fn copy_failed(state: &mut LunchPlanState, ctx: &mut ReducerContext<LunchPlanState>) {
    if state.copy_status != CopyStatus::Pending { return; }
    state.copy_status = match ctx.input.capability_error(WRITE_CLIPBOARD_TEXT) {
        Some(error) if error.code == "unsupported" => CopyStatus::Unsupported,
        _ => CopyStatus::Failed,
    };
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn quantity_stays_bounded_and_cannot_change_during_copy() {
        let mut state = LunchPlanState::default();
        state.decrease();
        assert_eq!(state.quantity, 1);
        for _ in 0..30 { state.increase(); }
        assert_eq!(state.quantity, 20);
        state.copy_status = CopyStatus::Pending;
        state.decrease();
        assert_eq!(state.quantity, 20);
    }

    #[test]
    fn memory_provider_round_trip_is_only_a_provider_contract_check() {
        let host = MemoryClipboardHost::default();
        assert_eq!(host.read_text().unwrap().text, None);
        host.write_text(ClipboardWriteTextRequest { text: "2".into() }).unwrap();
        assert_eq!(host.read_text().unwrap().text.as_deref(), Some("2"));
    }
}
{"id":"fission-tabs-1","index":1,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::state::{self, CopyStatus, LunchPlanState};

fission_component! {
    pub LunchPlan<LunchPlanState> {}
    view(_plan, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    SafeArea(child: Scroll(child: Container(
        child: Column(gap: tokens.spacing.m, children: [
            Text(cx.tr("lunch.title")).size(tokens.typography.heading2_size),
            Text(cx.tr("lunch.context")),
            SemanticsRegion(
                identifier: Some("lunch.quantity".to_string()),
                label: Some(cx.tr("lunch.quantity_label")),
                value: Some(state.quantity.to_string()),
                child: Text(state.quantity.to_string()).size(tokens.typography.heading1_size),
            ),
            Wrap(spacing: tokens.spacing.s, children: [
                Button(
                    child: Text(cx.tr("lunch.decrease")),
                    key: "decrease-lunch",
                    disabled: state.quantity == 1 || state.copy_status == CopyStatus::Pending,
                    on_press: reduce { state.decrease(); },
                ).semantics_identifier("lunch.decrease"),
                Button(
                    child: Text(cx.tr("lunch.increase")),
                    key: "increase-lunch",
                    disabled: state.quantity == 20 || state.copy_status == CopyStatus::Pending,
                    on_press: reduce { state.increase(); },
                ).semantics_identifier("lunch.increase"),
            ]),
            Button(
                child: Text(cx.tr("lunch.copy")),
                key: "copy-lunch-quantity",
                disabled: state.copy_status == CopyStatus::Pending,
                on_press: reduce { state::copy_quantity(state, cx); },
            ).semantics_identifier("lunch.copy"),
            if state.copy_status == CopyStatus::Pending {
                Spinner(
                    motion: Some(SpinnerMotion::Default),
                    label: cx.tr("lunch.copying"),
                )
            } else {
                Text(cx.tr(state.copy_status.key()))
            },
        ]),
    ).padding_all(tokens.spacing.l)))
}
{"id":"fission-tabs-1","index":2,"label":"src/translations.rs","value":"src-translations-rs"}
use std::collections::HashMap;
use fission::prelude::*;

pub fn create_env() -> Env {
    let mut env = Env::default();
    env.locale = Locale::from("en-US");
    for (locale, source) in [
        ("en-US", include_str!("../i18n/en-US.yaml")),
        ("es-ES", include_str!("../i18n/es-ES.yaml")),
    ] {
        let messages: HashMap<String, String> =
            serde_yaml::from_str(source).expect("valid checked-in translations");
        env.i18n.add_bundle(TranslationBundle { locale: Locale::from(locale), messages });
    }
    env
}
{"id":"fission-tabs-1","index":3,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
lunch.title: "Plan lunchbox quantities"
lunch.context: "Choose 1–20 lunchboxes, then copy the number into your own order. This app does not place an order or save the plan."
lunch.quantity_label: "Lunchbox quantity"
lunch.increase: "Add one lunchbox"
lunch.decrease: "Remove one lunchbox"
lunch.copy: "Copy quantity"
lunch.ready: "The clipboard has not been changed for this quantity."
lunch.copying: "Copying the quantity…"
lunch.copied: "Quantity copied."
lunch.unsupported: "This host cannot write to the clipboard. Use the displayed quantity."
lunch.failed: "The quantity could not be copied. The plan is still available."
{"id":"fission-tabs-1","index":4,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
lunch.title: "Planificar las cantidades de almuerzos"
lunch.context: "Elige entre 1 y 20 almuerzos y copia la cantidad en tu propio pedido. Esta aplicación no hace el pedido ni guarda el plan."
lunch.quantity_label: "Cantidad de almuerzos"
lunch.increase: "Añadir un almuerzo"
lunch.decrease: "Quitar un almuerzo"
lunch.copy: "Copiar la cantidad"
lunch.ready: "No se ha cambiado el portapapeles para esta cantidad."
lunch.copying: "Copiando la cantidad…"
lunch.copied: "Cantidad copiada."
lunch.unsupported: "Este host no puede escribir en el portapapeles. Usa la cantidad mostrada."
lunch.failed: "No se pudo copiar la cantidad. El plan sigue disponible."
{"id":"fission-tabs-1","index":5,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod state;
mod translations;

use app::LunchPlan;
use state::LunchPlanState;
use fission::prelude::*;

#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
    DesktopApp::<LunchPlanState, _>::new(LunchPlan)
        .with_env(translations::create_env())
        .run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<LunchPlanState, LunchPlan> {
    let app = MobileApp::<LunchPlanState, _>::new(LunchPlan)
        .with_env(translations::create_env());
    #[cfg(all(target_os = "android", debug_assertions))]
    let app = app.with_test_control_port(48761);
    app
}
#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> { mobile_app().run() }

#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
    let _ = mobile_app().run_with_android_app(app_handle);
}
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(start)]
pub fn run_web() -> Result<(), wasm_bindgen::JsValue> {
    console_error_panic_hook::set_once();
    WebApp::<LunchPlanState, _>::new(LunchPlan)
        .with_env(translations::create_env())
        .run()
        .map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":6,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod state;
mod translations;

use fission::prelude::*;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
    console_error_panic_hook::set_once();
    WebApp::<state::LunchPlanState, _>::new(app::LunchPlan)
        .with_env(translations::create_env())
        .mount("#fission-web-mount")
        .run()
        .map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
Add and remove a lunchbox, then copy the quantity. Paste it into a scratch text field in another application. The app does not place an order: its successful result means the clipboard write was acknowledged.
If the browser blocks clipboard access in the embedded preview, it must show the actual failure, not install a memory host to make the screen look successful.
Show the app preview
Hide the app preview

2. Run the small tests, then drive the native shell

Start with the tests that do not need a device:
cargo test
fission doctor android --project-dir .
fission test --target android --project-dir .
The first test checks the quantity rule and the pending guard. The second checks only the memory provider's text round-trip; it does not exercise the app's callback registration, the Android clipboard or an OS prompt. fission test is the generated host smoke path, not the whole user journey.
Run a fresh debug app and forward its loopback test port. Keep the app in the foreground; do not expose the control server on a public network.
fission run --target android --device <adb-serial> --project-dir .
In another terminal:
adb -s <adb-serial> forward tcp:48761 tcp:48761
curl --fail http://127.0.0.1:48761/health
curl --fail -H 'Content-Type: application/json' \
  --data '{"cmd":"GetTree"}' http://127.0.0.1:48761/cmd
curl --fail -H 'Content-Type: application/json' \
  --data '{"cmd":"TapSelector","query":{"selector":{"kind":"semantic_identifier","identifier":"lunch.increase"}}}' \
  http://127.0.0.1:48761/cmd
curl --fail -H 'Content-Type: application/json' \
  --data '{"cmd":"WaitForValue","query":{"selector":{"kind":"semantic_identifier","identifier":"lunch.quantity"}},"value":"2","timeout_ms":3000}' \
  http://127.0.0.1:48761/cmd
curl --fail -H 'Content-Type: application/json' \
  --data '{"cmd":"TapSelector","query":{"selector":{"kind":"semantic_identifier","identifier":"lunch.copy"}}}' \
  http://127.0.0.1:48761/cmd
curl --fail -H 'Content-Type: application/json' \
  --data '{"cmd":"WaitForText","text":"Quantity copied.","timeout_ms":5000}' \
  http://127.0.0.1:48761/cmd
These requests assume a fresh launch at quantity one and the configured English locale. Inspect each response's status; HTTP success alone is not an assertion that the selector or action succeeded. A SelectorError or Error is a failed check, even if the request returned HTTP 200.
The native tree should expose lunch.quantity with value 2, and Copy should complete through the typed success callback. Paste into another app to verify the actual Android clipboard contents. A memory-provider unit test cannot replace that check.
Show the app preview
Hide the app preview

3. Capture evidence and test the failure paths

The test server can return a screenshot to the caller rather than writing a phone-local file:
curl --fail -H 'Content-Type: application/json' \
  --data '{"cmd":"CaptureScreenshot"}' http://127.0.0.1:48761/cmd
The response contains PNG bytes as png_base64, dimensions and a status. Save those bytes with the client that collects your test artifacts. Inspect the image, but keep the semantic value and interaction result with it: a screenshot of a button does not prove it activated.
Check the lower and upper quantity limits, a clipboard error, a second attempted copy whilst pending, background/foreground transitions and a fresh launch. Quantity is not persisted, so a fresh app starts at one. Repeat the interaction on an emulator and a phone; then check text scaling and keyboard or accessibility input where the product needs them.
fission build --target android --project-dir . --release
adb -s <adb-serial> forward --remove tcp:48761
Release compilation is a separate check. The tutorial does not opt release builds into test control, and the release environment should not set FISSION_TEST_CONTROL_PORT. Do not ship an automation endpoint merely because it was convenient during QA.
Record the source revision, target, device/Android version, exact scenario and observed result. Keep unit, provider, host smoke, native interaction and visual evidence separate. A passing check at one layer does not turn the others into completed work.

Current references