# `mix mob.selftest`
[🔗](https://github.com/genericjam/mob_dev/blob/master/lib/mix/tasks/mob.selftest.ex#L1)

Attach to the deployed app on each selected device and run every activated
plugin's `Mob.Plugin.SelfTest` on it, over distribution.

    mix mob.selftest                       # the one connected emulator/simulator
    mix mob.selftest --device emulator-5554
    mix mob.selftest --all-devices --timeout 10000

The app must be deployed (`mix mob.deploy`) with the plugins activated in
`mob.exs`; a self-test is only on the device if the build that is running
included it. Each plugin's `selftest: Module` from its manifest is called
with `%{platform: :ios | :android, device: :simulator | :emulator |
:physical}` and gets one line in a table per device: `pass`, `FAIL` with
the reason, or `skip` with why (a plugin without a self-test is a skip,
so it is visible). A self-test that raises, exits, times out or returns
something outside the contract is a `FAIL`.

Before the tests run, the permissions the manifests declare are granted
on emulators and simulators (`adb shell pm grant`, `xcrun simctl privacy
grant`), so no system prompt stands between a self-test and its native
code. The app is then relaunched (as `mix mob.connect` does), because a
simulator may terminate an app whose privacy settings changed.
`--no-restart` attaches to the app as it is and grants nothing.

## Options

  * `--device` / `--only` (`-d`) — target a device by serial/udid
    (serial, udid or short id). Repeatable
  * `--all-devices`  — every emulator and simulator
  * `--all-physical` — every physical device (with `--all-devices`: everything)
  * `--ios-only` / `--android-only` — restrict discovery to one platform
  * `--timeout MS` — per self-test, in milliseconds (default: 30000)
  * `--no-restart` — do not relaunch the app before testing (and do not
    grant permissions)
  * `--cookie C` — dist cookie (default: the app's private cookie)

With no selection flags exactly one emulator/simulator is picked, and a
device another `agent-device` session holds is left alone unless named.

## Exit status

Non-zero when any self-test failed, or a selected device's node could not
be reached (a test that could not run is not a test that passed).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
