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.
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
withServerpod test helperdart testWhy Serverpod
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.