> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quiesco.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# チュートリアル：ToDoアプリをテストする

> 3画面の小さなToDoアプリにE2Eテストを一歩ずつ書いていきます。テストID、画面をまたぐフロー、バックドア、リセット、失敗の読み方。

このチュートリアルは動くアプリから始めて、Web、iOS、Androidでそのまま動く8つのテストを書き上げます。その過程で、典型的なテストに必要なことを一通り使います。テストIDで要素を見つける、画面を移動する、フォームに入力する、バックドアでデータを用意する、失敗を読み解く、の5つです。

テストは[テストランナー](https://docs.quiesco.dev/ja/runners.md)ごとに1通りずつ書いてあります。このページでプロジェクトを用意してから、1つ選んでください。手順は同じで、違うのはテストのコードだけです。

所要時間は約30分です。Node.js 24+が必要で、iOSとAndroidでは[クイックスタート](https://docs.quiesco.dev/ja/quickstart.md)に挙げたツールも必要です。

## アプリ

アプリは、3つの画面からなるExpo Routerアプリです。リポジトリにはテストランナーごとに1つずつ、[`todo-tutorial-vitest`](https://github.com/h2nology/quiesco/tree/main/examples/todo-tutorial-vitest)、[`todo-tutorial-jest`](https://github.com/h2nology/quiesco/tree/main/examples/todo-tutorial-jest)、[`todo-tutorial-cucumber`](https://github.com/h2nology/quiesco/tree/main/examples/todo-tutorial-cucumber)があり、違うのはテストだけです。

![2件のToDoがあり、1件にチェックが入ったToDoリストと、New todoボタン](https://mintcdn.com/shift-14cc7601/yVeoZoE7ayMC30L-/images/tutorial/list.png?fit=max\&auto=format\&n=yVeoZoE7ayMC30L-\&q=85\&s=dd7f1ba50e656cb2bdecc2b0e255fc07)

リスト（/）

![タイトル欄、メモ欄、Saveボタンがある新規ToDoフォーム](https://mintcdn.com/shift-14cc7601/yVeoZoE7ayMC30L-/images/tutorial/new-todo.png?fit=max\&auto=format\&n=yVeoZoE7ayMC30L-\&q=85\&s=bd63d510aeeaa2bc82d0ce4e05e0683d)

新規ToDo（/new）

![Mark as doneボタンとDelete todoボタンがあるToDoの詳細](https://mintcdn.com/shift-14cc7601/yVeoZoE7ayMC30L-/images/tutorial/details.png?fit=max\&auto=format\&n=yVeoZoE7ayMC30L-\&q=85\&s=47abf7bc52081a224b11b9fb960d9469)

詳細（/todo/\[id]）

* **リスト**はすべてのToDoをチェックボックス付きで表示し、完了した件数も示します。**New todo**でフォームが開き、ToDoをタップするとその詳細が開きます。
* **新規ToDo**ではタイトルと、任意でメモを入力します。保存には少し時間がかかり（バックエンドへのリクエストの代わりです）、その後リストに戻ります。
* **詳細**は1件のToDoを表示し、2つのボタンがあります。完了にする（または未完了に戻す）ボタンと、削除するボタンです。

ToDoはメモリ上にあり（`src/store.ts`）、起動するたびに空のリストから始まります。

## プロジェクトを用意する

使うテストランナーのサンプルをリポジトリからコピーしてインストールします。

```sh Vitest theme={null}
npx degit h2nology/quiesco/examples/todo-tutorial-vitest quiesco-todo
cd quiesco-todo
npm install
```

```sh Jest theme={null}
npx degit h2nology/quiesco/examples/todo-tutorial-jest quiesco-todo
cd quiesco-todo
npm install
```

```sh Cucumber theme={null}
npx degit h2nology/quiesco/examples/todo-tutorial-cucumber quiesco-todo
cd quiesco-todo
npm install
```

アプリを触ってみたければ`npm run web`（dev clientなら`npm start`）で起動できます。プロジェクトはQuiesco向けにセットアップ済みです。`npx quiesco init --runner <runner>`と[クイックスタート](https://docs.quiesco.dev/ja/quickstart.md)の手順で作られるものと同じです。

| ファイル | 役割 |
| - | - |
| `index.ts` | `expo-router/entry`より前に`@quiesco/agent`をインポートし、最初のレンダリングからエージェントがアプリを把握できるようにする |
| `metro.config.js` | `withQuiesco()`：e2eビルド（`EXPO_PUBLIC_QUIESCO=1`）では本物のエージェント、それ以外では何もしないスタブ |
| `app.json` | `@quiesco/expo-plugin`を登録し、`quiesco.config.mts`が指すbundle id / packageを設定する |
| `src/app/_layout.tsx` | アプリを`<QuiescoRoot>`でラップし、e2eビルドでだけ`src/e2e.ts`を読み込む |
| `quiesco.config.mts` | 各プラットフォームでのアプリの場所：Webエクスポート、シミュレータービルド、APK |
| `vitest.config.mts`、`jest.config.cjs`、`cucumber.mjs`のいずれか | テストランナーの設定：どのテストファイルをQuiescoで実行するか |
| `package.json` | `e2e:*`スクリプト：`e2e:web`、`e2e:build:ios`、`e2e:ios`、`e2e:build:android`、`e2e:android` |

## テストランナーを選ぶ

> [card] [Vitest（推奨）](https://docs.quiesco.dev/ja/tutorial-vitest.md)
>
> TypeScriptでテストを書き、アプリは`app`フィクスチャーで受け取ります。

> [card] [Jest](https://docs.quiesco.dev/ja/tutorial-jest.md)
>
> JavaScriptでテストを書き、アプリはグローバルの`quiesco.app`から操作します。

> [card] [Cucumber](https://docs.quiesco.dev/ja/tutorial-cucumber.md)
>
> Gherkinでシナリオを、TypeScriptでステップ定義を書きます。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.