Skip to content

Testing

Last updated View as MarkdownAgent setup

The Workers platform provides complementary tools for testing different parts of your application. For most projects, use the Workers Vitest integration for unit tests and the createTestHarness() API for integration tests.

Unit tests

Use the Workers Vitest integration for fast feedback while testing individual functions and modules. Tests run inside the Workers runtime, so your test code can access bindings and runtime APIs directly.

The Workers Vitest integration provides:

  • Fast feedback while testing individual functions and modules.
  • Direct assertions against binding state, such as values written to KV, R2, D1, or Durable Objects.
  • Direct calls to Durable Objects and other runtime APIs.

To set up unit tests, refer to Write your first Vitest test.

Integration tests

Use the createTestHarness() API to exercise one or more Workers as a whole and test how they interact with each other and with external services.

The integration test harness provides:

  • Confidence from exercising production Worker builds.
  • Coverage through configured HTTP routes across Workers.
  • Compatibility with any Node.js test runner and tools such as Playwright or MSW.

To set up integration tests, refer to Get started with the integration test harness.

Was this helpful?