1---
2title: Testing
3description: How Alchemy tests work — real clouds by default, local emulators on demand, one Stack deploy per suite, isolated stages, deploy → assert → destroy.
4---
5
6Alchemy tests run against real clouds by default — no mocks. A suite deploys a real Stack once, runs assertions against live resources, and tears it back down: deploy → assert → destroy. The same suite can also run entirely on your machine — see [Local mode](#local-mode-dev-true) below.
7
8## One deploy per suite
9
10Deploy once in `beforeAll`, share the outputs handle across every test, destroy in `afterAll`:
11
12```typescript
13const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
14 providers: Cloudflare.providers(),
15 state: Cloudflare.state(),
16});
17
18const stack = beforeAll(deploy(Stack));
19afterAll(destroy(Stack));
20
21test(
22 "serves the deployed URL",
23 Effect.gen(function* () {
24 const { url } = yield* stack;
25 const res = yield* HttpClient.get(url);
26 expect(res.status).toBe(200);
27 }),
28);
29```
30
31For the full walkthrough, see [Testing a Stack](/testing/testing-a-stack).
32
33For every option, hook, and variant, see the [Test harness](/testing/test-harness) reference.
34
35## Stage isolation
36
37Tests default to `test_$USER` (e.g. `test_sam`), matching how
38`alchemy deploy` uses `live_$USER` and `alchemy dev` uses
39`dev_$USER` — so they never touch your live or local-dev
40deployments, and two people running the same suite don't collide. A
41unique stage per PR lets CI suites run in parallel against the same
42account:
43
44```typescript
45Test.make({ providers, stage: "ci-pr-42" });
46```
47
48The per-call form is covered in [Test harness → stage](/testing/test-harness#stage).
49
50## Local mode (`dev: true`)
51
52The harness has the same local-dev mode as [`alchemy dev`](/environments/local-development). It's off by default; flip it on and the whole suite runs against local emulators — Cloudflare Workers, Durable Objects, KV, R2, D1, Queues, and Workflows in workerd, AWS Lambda/ECS and the emulated AWS surface in a local Docker emulator — with no cloud calls:
53
54```typescript
55Test.make({
56 providers: Cloudflare.providers(),
57 dev: true,
58});
59```
60
61Nothing else changes: `deploy(Stack)` boots the stack locally and the tests drive `http://localhost:<port>` instead of the cloud. There's no need for a separate testing setup (e.g. workerd + a vitest plugin) — the harness runs your real Stack in the same local runtimes `alchemy dev` uses. Omit the flag and set `ALCHEMY_DEV=1` in your shell to keep one test file that runs locally on your laptop and live in CI.
62
63Full option semantics: [Test harness → dev](/testing/test-harness#dev).
64
65## Where next
66
67- [Testing a Stack](/testing/testing-a-stack) — deploy a Stack and drive it over HTTP, end to end.
68- [Testing Providers](/testing/testing-providers) — exercise a provider's create/update/replace/delete with `test.provider`.
69- [Test harness](/testing/test-harness) — every `Test.make` option, hook, and variant.
70- [Observability](/testing/observability) — wire exporters, monitors, and alarms into the same Stack.
71- [Tutorial Part 3](/cloudflare/tutorial/part-3) — your first integration test, walked through step by step.
72- [Tutorial Part 4](/cloudflare/tutorial/part-4) — running the same tests against local emulators with `dev: true`.