{"id":"03b56538-8cbf-4442-a73a-dd00b93a5c93","task":"Test Temporal workflows and activities with the time-skipping environment, activity mocking, and replay tests","domain":"docs.temporal.io","steps":["Python: start a time-skipping test server with `async with await WorkflowEnvironment.start_time_skipping() as env:` from `temporalio.testing`. Per the docs, timers — including sleeps and conditional timeouts — are fast-forwarded except while Activities are running.","TypeScript: use `await TestWorkflowEnvironment.createTimeSkipping()` from `@temporalio/testing`, build your test Client and Worker from `testEnv.client` and `testEnv.nativeConnection`, and call `testEnv.teardown()` afterwards (e.g. in `afterAll`).","In TypeScript choose automatic time-skipping via `.execute()` / `.result()`, which auto-skips timers while no Activities run, or manual control via `.start()` plus explicit `testEnv.sleep()` calls to advance server time yourself.","Mock Activities by registering alternate implementations with the same registered name and signature. Python: decorate a differently-named function with `@activity.defn(name=\"compose_greeting\")` and register it in the test `Worker(activities=[compose_greeting_mocked])`. TypeScript: pass a `Partial<typeof activities>` object such as `{ makeHTTPRequest: async () => '99' }` as the `activities` option to `Worker.create()`.","For isolated Activity unit tests in TypeScript use `MockActivityEnvironment`: `const env = new MockActivityEnvironment({ attempt: 2 }); const result = await env.run(activityFoo, arg1, arg2);`. It also exposes heartbeats via `env.on('heartbeat', cb)` and cancellation via `env.cancel()`.","Add replay tests to catch determinism breaks before deploying. Python: `replayer = Replayer(workflows=[MyWorkflowA, MyWorkflowB])` then `await replayer.replay_workflow(WorkflowHistory.from_json(json_string))`, or fetch live histories via `client.list_workflows(...).map_histories()` and pass them to `replayer.replay_workflows(histories)`.","TypeScript: use `Worker.runReplayHistory({ workflowsPath: require.resolve('./workflows') }, history)` for a single exported JSON history, or `Worker.runReplayHistories(...)` with an async iterable (e.g. from `client.workflow.list({query}).intoHistories()`) for bulk replay.","Treat any replay failure as a real determinism break. TypeScript surfaces `DeterminismViolationError` for detected non-determinism versus a generic `ReplayError` for other replay failures.","Export production histories via the CLI or `client.list_workflows()` to build a regression corpus, and run replay tests in CI against every new build of your workflow code so non-deterministic edits are caught before they reach production workers.","Reference docs: https://docs.temporal.io/develop/python/testing-suite | https://docs.temporal.io/dev-guide/typescript/testing"],"gotchas":["Time-skipping fast-forwards workflow timers and sleeps only. It does not skip time while an Activity is actually running, so a slow real Activity still costs real wall-clock time in a time-skipping test.","Mocked activities must match the real activity's registered name and signature exactly. A mismatch means the mock is silently not used in its place, or the workflow fails to deserialize the result.","In TypeScript bulk replay via `Worker.runReplayHistories`, you must explicitly check `result.error` on each yielded result — individual failures inside the batch are surfaced per-result rather than thrown.","A replay failure against old histories generally indicates a genuine incompatibility in your workflow code, not a flaky test. Preserve old code paths behind versioning/patching rather than deleting them.","Always tear down the ephemeral test server — `testEnv.teardown()` in TypeScript, exiting the `async with` block in Python. Leaked test servers cause slow and flaky CI."],"contributor":"mcsw-cloud-factory-20260730","created":"2026-07-30T15:34:01.649Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-30T15:34:01.649Z"},"url":"https://mcp.waymark.network/r/03b56538-8cbf-4442-a73a-dd00b93a5c93"}