serverpod-testing

Test Serverpod endpoints and business logic with full server context.

3.2k|369|Updated May 22, 2021
One-click install
npx skills add https://github.com/serverpod/serverpod --skill serverpod-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serverpod-testing
Source: https://github.com/serverpod/serverpod/tree/main/packages/serverpod/skills/serverpod-testing
Command: npx skills add https://github.com/serverpod/serverpod --skill serverpod-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the problem of writing reliable integration-style tests for Serverpod endpoints and business logic without manually wiring server context like DB, caching, authentication, and streams.

Core Features & Use Cases

  • Server-backed endpoint testing: Call generated endpoints inside tests usingServerpod so requests run with realistic server lifecycle and validations.
  • Session building for auth scenarios: Use sessionBuilder.copyWith to test authenticated vs unauthenticated behavior deterministically.
  • DB seeding and safe rollback: Seed data in setUp blocks and rely on transaction rollback (or configure afterAll/disabled when concurrency requires it).
  • Stream testing utilities: Verify real-time stream behavior using flushEventQueue to ensure yields are executed before asserting.
  • Business-logic testing with Session: Test non-endpoint logic by creating and passing a Session directly.

Quick Start

Use the serverpod-testing skill to run your tests by calling withServerpod and invoking generated endpoint test tools from test_tools.

Frequently Asked Questions about serverpod-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Serverpod endpoints with database seeding and rollback?

To test Serverpod endpoints with database seeding and rollback, use withServerpod to seed data in setUp blocks and rely on transaction rollback semantics. Configure afterAll or disabled rollback when concurrency requires it to ensure deterministic integration testing.

Can I test authenticated vs unauthenticated behavior in Serverpod integration tests?

Yes, you can test authenticated vs unauthenticated behavior deterministically in Serverpod integration tests by using the sessionBuilder.copyWith method to override authentication context within your test cases.

What is the best way to verify real-time stream delivery in Serverpod tests?

The best way to verify real-time stream delivery in Serverpod tests is to use stream testing utilities like flushEventQueue, which ensures yields are fully executed before assertions are made. This guarantees accurate testing of real-time message delivery.

Do I need a generated test tools import to run Serverpod endpoint tests?

Yes, you need the generated test tools import to run Serverpod endpoint tests, as it provides the necessary withServerpod sessionBuilder and endpoint configurations to satisfy startup and rollback requirements for reliable execution.

How do I test Serverpod business logic that is not inside an endpoint?

To test Serverpod business logic that is not inside an endpoint, create and pass a Session object directly to your non-endpoint logic. This allows you to leverage full server context including caching and database access during testing.