Testing framework

Test your endpoints and database logic with a first-class Dart testing framework: boot a real Serverpod in your tests and call endpoints directly, with no HTTP mocking.

Get Started

Endpoint testing

Backend tests usually mean mocking HTTP calls and writing fake data by hand. The mocks will slowly stop matching how the server actually behaves. The test stays green while the real thing is broken.

Serverpod's test helper boots a real server and database, so your tests call the same endpoints your Flutter app uses and check typed results. Nothing to mock, no fake data to keep in sync.

How it works

1Wrap your tests with withServerpod

The withServerpod helper gives you a session builder and typed access to every endpoint.

withServerpod('Given CompanyEndpoint', (sessionBuilder, endpoints) {
  test('when list is called then it returns companies', () async {
    var companies = await endpoints.company.list(sessionBuilder);
    expect(companies, isNotEmpty);
  });
});

2Run against a real database

Each test runs against a real database and is isolated, so tests do not leak state into one another.

3Run with dart test

dart test

Integration tests

Your endpoints run against a real server and database, so a passing test means the actual code path works, not a mock of it.

Authenticated endpoints

The session builder can sign in a test user, so you can test endpoints that require login and specific scopes.

Streams and database

Because you call endpoints directly, you can test streaming methods and database-backed logic with the same helper.

Everything included

The withServerpod test helper
Typed endpoint calls
A real database per run
Rollback isolation by default
Authenticated session builders
Streaming endpoint testing
Unit and integration tests, separated
Runs under dart test
CI-friendly

Why Serverpod

Full-stack type safety. Tests call the same generated endpoints your app does, checked at compile time.
Open source. Tests run against a real Serverpod you control, with nothing hosted or hidden.
Zero-configuration deployments. The same code you test ships to Serverpod Cloud unchanged.

Works with

dart test your CI/CD pipeline

Frequently asked questions

How do I test Serverpod endpoints?

Wrap your tests with withServerpod and call the endpoints directly through the provided handle.

Does it use a real database?

Yes. Tests run against a real database and are isolated so they do not affect each other.

Do I need to mock HTTP?

No. You call endpoints in-process, so there is no HTTP layer to mock.

Can I test authenticated endpoints?

Yes. The session builder can sign in a test user with the required scopes.

When should I not use this?

For pure unit tests of a standalone function, a plain dart test is enough. withServerpod is for endpoint and database-backed tests.

Stay up-to-date

Our mailing list keeps you up-to-date with new Serverpod releases and features. You will get an email about once a month or when something big is happening. We promise to keep it relevant and we have a strict no-spam policy.

© 2026 Serverpod AB
Built with Serverpod - Hosted on Serverpod Cloud