serverpod_test library

Classes

AuthenticationOverride
An override for the authentication state in a test session.
InternalServerpodSession
A serverpod session used internally by the test tools. This is needed to modify the transaction which is not mutable on the Session base class.
InternalTestEndpoints
Internal test endpoints interface that contains implementation details that should only be used internally by the test tools.
InternalTestSessionBuilder
Internal test session that contains implementation details that should only be used internally by the test tools.
TestServerpod<T extends InternalTestEndpoints>
A facade for the real Serverpod instance.
TestSessionBuilder
A test specific builder to create a Session that for instance can be used to call database methods. The builder can also be passed to endpoint calls. The builder will create a new session for each call.
TestStreamManager<OutputStreamType>
Manages streams in the generated endpoints. Used by the generated code.

Enums

RollbackDatabase
Options for when to rollback the database during the test lifecycle.
TestServerOutputMode
Options for controlling test server output during test execution.

Constants

defaultIntegrationTestTag → const String
The default integration test tag used by withServerpod.
isTestGroup → const _IsTestGroup
Used to annotate a test framework function that runs a group of tests.

Functions

buildWithServerpod<T extends InternalTestEndpoints>(String testGroupName, TestServerpod<T> testServerpod, {required RollbackDatabase? maybeRollbackDatabase, required bool? maybeEnableSessionLogging, required List<String>? maybeTestGroupTagsOverride, required Duration? maybeServerpodStartTimeout, required TestServerOutputMode? maybeTestServerOutputMode}) → void Function(TestClosure<T> )
Builds the withServerpod test helper. Used by the generated code. Note: The testGroupName parameter is needed to enable IDE support.
callAwaitableFunctionAndHandleExceptions<T>(Future<T> call()) Future<T>
Test tools helper to not leak exceptions. Used for calls to awaitable functions with non-stream input parameters. Used by the generated code.
callAwaitableFunctionWithStreamInputAndHandleExceptions<T>(Future<Stream<T>> call()) Future<T>
Test tools helper to not leak exceptions. Used for calls to awaitable functions with streams as input parameters. Used by the generated code.
callStreamFunctionAndHandleExceptions<T>(Future<void> call(), StreamController controllerToCloseUponFailure) Future<void>
Test tools helper to not leak exceptions. Used for calls to functions that return a stream, regardless of input parameters. Used by the generated code.
flushEventQueue() Future<void>
Test helper to flush the event queue. Useful for waiting for async events to complete before continuing the test.
testObjectToJson(dynamic object) → dynamic
A test helper that serializes objects to JSON before passing it to EndpointDispatch. Used by the generated code.

Typedefs

TestClosure<T> = void Function(TestSessionBuilder testSession, T endpoints)
The test closure that is called by the withServerpod test helper.

Exceptions / Errors

ConnectionClosedException
Thrown if a stream connection is closed with an error. For example, if the user authentication was revoked.
InitializationException
Thrown when the withServerpod helper could not be initialized.
InvalidConfigurationException
Thrown when an invalid configuration state is found.
ServerpodInsufficientAccessException
The authentication key provided did not have sufficient access.
ServerpodUnauthenticatedException
The user was not authenticated.