testing library

Test support for package:better_effect.

Import this library from test code instead of the main entrypoint when you need Runtime harnesses, deterministic gates, event recording, Exit matchers, or backend contract verification.

Classes

AutoInjectorBackend
The default ResolverBackend, powered by package:auto_injector.
Binding
A declarative service registration used inside a Module.
CancellationSignal
A cooperative cancellation signal exposed to an active Effect.
CleanupFailureDiagnostic
Describes a cleanup failure reported after an Effect outcome was known.
CleanupFailureEvent
Runtime-observer projection of an existing cleanup diagnostic.
Effect<A extends Object, E extends Object>
A lazy computation that can succeed with A or fail with E.
EffectContext<E extends Object>
The capabilities available inside Effect.result.
EffectExecution<A extends Object, E extends Object>
A managed handle for one Effect execution.
EffectLocal<T extends Object>
A runtime-local value inherited by nested Effects.
EffectLocalBinding
A heterogeneous, type-safe local binding.
ExecutionEndEvent
Emitted synchronously after physical work and Scope cleanup finish.
ExecutionStartEvent
Emitted synchronously immediately before an Effect runner starts.
Exit<A extends Object, E extends Object>
The complete outcome of running an Effect.
ExitDefect<A extends Object, E extends Object>
An Effect terminated because of an unexpected defect.
ExitFailure<A extends Object, E extends Object>
An Effect completed with an expected, typed failure.
ExitInterrupted<A extends Object, E extends Object>
Execution or runtime ownership ended without a success or typed failure.
ExitSuccess<A extends Object, E extends Object>
An Effect completed successfully.
Failure<S extends Object, F extends Object>
Error Result.
InterruptionEvent
Emitted once when a managed execution first receives cancellation.
Module
A composable collection of service bindings.
RecordingRuntimeObserver
Records Runtime events in callback order for assertions and diagnostics.
ResolverBackend
Backend contract used by Runtime to register and resolve services.
ResolverBackendContractReport
Complete compatibility report for one backend implementation.
ResolverBackendContractResult
Result of one backend compatibility scenario.
ResolverBackendDisposalProbe
Optional fixture used to prove that backend-owned instantiated services are disposed when the backend closes.
ResolverBackendOverlayFactory
Optional backend capability used by RuntimeExecutionModuleOps.
ResourceReleaseEvent
Describes release of one Module or Effect resource.
ResultDart<S extends Object, F extends Object>
Base Result class
Runtime
Executes Effects against the environment built from a Module.
RuntimeEventContext
Immutable execution and metadata projection shared by Runtime events.
RuntimeObserver
SDK-neutral, synchronous Runtime instrumentation.
RuntimeObserverError
A callback failure that was isolated from execution semantics.
Scope
Owns finalizers, resources, and child Scopes.
ServiceAcquireEvent
Describes acquisition of one Module or Effect resource.
ServiceKey<T extends Object>
A typed name for distinguishing multiple implementations of the same type.
ServiceResolveEvent
Describes one service-resolution attempt.
Services
A read-only, callable view of the services available in a Runtime.
Success<S extends Object, F extends Object>
Success Result.
TestEventRecorder<T extends Object>
Records an ordered sequence such as resource acquisition and cleanup events.
TestGate<T extends Object>
A deterministic one-value gate for coordinating asynchronous tests.
TestRuntime
A test-owned Runtime with event recording and deterministic cleanup.
TestSignal
A deterministic signal for tests that only need to release a wait point.
Unit
Used instead of void as a return statement for a function when no value is to be returned.

Enums

InterruptionSource
Which owner requested cooperative interruption.
Lifetime
Controls how a constructor-backed service is instantiated.
ResolverBackendContractCase
Behavioral scenarios shared by ResolverBackend implementations.
ResourceAcquisitionSource
Which API acquired a scoped resource.
RuntimeObserverCallback
Identifies the observer callback that raised an instrumentation error.
RuntimeState
Lifecycle state of a Runtime.
ServiceResolutionSource
How a service request was satisfied.

Extensions

AsyncResultDartEffectInterop on AsyncResultDart<A, E>
Convert an asynchronous Result into an Effect.
AsyncResultDartExtension on AsyncResultDart<S, F>
AsyncResultDart<S, E> represents an asynchronous computation.
EffectTransformOps on Effect<A, E>
Transformations available on every Effect.
FlattenAsyncResultExtension on AsyncResultDart<ResultDart<S, F>, F>
Extension to flatten a nested AsyncResultDart into a single AsyncResultDart.
FlattenResultExtension on ResultDart<ResultDart<S, F>, F>
Extension to flatten a nested ResultDart into a single ResultDart.
FutureResultExtension on Future<S>
Extension on Future<S> to convert it into an AsyncResultDart<S, Exception>.
FutureResultExtensionVoid on Future<void>
Extension on Future<void> to convert it into an AsyncResultDart<Unit, Exception>.
ResultDartEffectInterop on ResultDart<A, E>
Convert a synchronous Result into a lazy Effect value.
ResultObjectExtension on W
Adds methods for converting any object into a Result type (Success or Failure).
RuntimeExecutionModuleOps on Runtime
Execution-scoped Module operations for a long-lived Runtime.

Constants

unit → const Unit
Used instead of void as a return statement for a function when no value is to be returned.

Functions

expectExitDefect<A extends Object, E extends Object>(Exit<A, E> exit) → ({Object defect, StackTrace stackTrace})
Extract a defect and stack trace or throw an assertion-oriented exception.
expectExitFailure<A extends Object, E extends Object>(Exit<A, E> exit) → E
Extract a typed failure or throw an assertion-oriented exception.
expectExitInterrupted<A extends Object, E extends Object>(Exit<A, E> exit) → void
Assert an interrupted outcome without depending on a test framework.
expectExitSuccess<A extends Object, E extends Object>(Exit<A, E> exit) → A
Extract a successful value or throw an assertion-oriented exception.
inspectResolverBackendContract({required ResolverBackendTestFactory createBackend, ResolverBackendDisposalProbeFactory? createDisposalProbe}) Future<ResolverBackendContractReport>
Run every ResolverBackend scenario and return a detailed report.
isExitDefect<A extends Object, E extends Object>([Object? defect = _unspecified]) → Matcher
Match an ExitDefect with optional defect matching.
isExitFailure<A extends Object, E extends Object>([Object? error = _unspecified]) → Matcher
Match an ExitFailure with optional typed-error matching.
isExitInterrupted<A extends Object, E extends Object>() → Matcher
Match an ExitInterrupted.
isExitSuccess<A extends Object, E extends Object>([Object? value = _unspecified]) → Matcher
Match an ExitSuccess with optional value matching.
runResolverBackendContractTests({required ResolverBackendTestFactory createBackend, ResolverBackendDisposalProbeFactory? createDisposalProbe}) Future<void>
Acceptance-test-style alias intended for one ordinary package:test test.
verifyResolverBackendContract({required ResolverBackendTestFactory createBackend, ResolverBackendDisposalProbeFactory? createDisposalProbe}) Future<void>
Verify a backend contract and throw ResolverBackendContractException when any required scenario fails.

Typedefs

AsyncResult<S extends Object> = AsyncResultDart<S, Exception>
A typedef for an asynchronous Result, simplifying the usage of AsyncResultDart with Exception as the default failure type.
AsyncResultDart<S extends Object, F extends Object> = Future<ResultDart<S, F>>
AsyncResultDart<S, E> represents an asynchronous computation.
CleanupFailureObserver = FutureOr<void> Function(CleanupFailureDiagnostic diagnostic)
Receives cleanup failures without changing the main Effect outcome.
EffectBody<A extends Object, E extends Object> = FutureOr<A> Function(EffectContext<E> use)
A lazy Effect body with access to contextual services and typed failures.
ReleaseFailure = ({Object error, StackTrace stackTrace})
A finalizer failure captured while closing a Scope.
ResolverBackendDisposalProbeFactory = ResolverBackendDisposalProbe Function()
Creates a backend with backend-specific disposal instrumentation.
ResolverBackendTestFactory = ResolverBackend Function()
Creates a fresh backend for one compatibility scenario.
ResourceAcquire<T extends Object> = FutureOr<T> Function(Services services)
Creates a resource using services already available in the module.
ResourceRelease<R extends Object> = FutureOr<void> Function(R resource, Exit<Object, Object> exit)
Releases a resource with the outcome that closed its owning Scope.
Result<S extends Object> = ResultDart<S, Exception>
A typedef for a Result that simplifies the usage of ResultDart with Exception as the default failure type.
RuntimeObserverErrorHandler = void Function(RuntimeObserverError error)
Reports failures raised by RuntimeObserver callbacks.
ScopeFinalizer = FutureOr<void> Function(Exit<Object, Object> exit)
A cleanup callback registered with a Scope.
TestCleanupRegistrar = void Function(Future<void> cleanup())
Registers an asynchronous cleanup callback with the surrounding test runner.

Exceptions / Errors

ActiveTestExecutionsException
Raised when a test leaves managed physical work active.
BetterEffectTestExpectationException
Framework-independent failure used by typed Exit extractors.
CompositeDefect
Preserves a primary defect together with another defect raised during cleanup.
DuplicateServiceBindingException
Thrown when a Module contains more than one binding for the same service.
RecordingRuntimeObserverDisposedException
Raised when a disposed recorder is used again.
ResolverBackendContractException
Aggregate failure raised by verifyResolverBackendContract.
ResolverBackendContractViolation
One failed contract assertion.
ResolverBackendOverlayUnsupportedException
Reported when a custom backend cannot create an execution-local overlay.
ResourceAcquisitionException
Identifies the Module resource whose acquisition failed.
RuntimeClosedException
Thrown when an operation is attempted after a Runtime stops accepting work.
RuntimeEventWaitTimeoutException
Raised when RecordingRuntimeObserver.next did not observe a matching event.
ScopeClosedException
Thrown when new work is added to a Scope after closing starts.
ScopeReleaseException
Aggregates one or more defects raised while releasing scoped resources.
TestEventSequenceException<T extends Object>
TestGateAlreadyCompletedException