testing library

Test utilities for dust_server.

import 'package:dust_server/testing.dart';

void main() {
  test('lists todos', () async {
    final client = TestClient(buildApp());
    addTearDown(client.close);

    (await client.get('/todos').send())
        ..assertOk()
        ..assertJsonContains({'count': 0});
  });
}
  • TestClient(router) — in-process, no socket, sub-millisecond.
  • TestClient.serve(router) — real HTTP on port 0, catches wire bugs.

Separate from server.dart so production code never pulls test utilities.

Classes

TestClient
Drives a Router through either an in-process handler or real HTTP.
TestRequest
A request being built for a TestClient.
TestResponse
The response from a TestClient request.

Functions

buildRequest(String method, String path, {Map<String, String> headers = const {}, Object? body, Map<String, String> pathParameters = const {}, Map<String, Object> context = const {}}) Request
Builds a shelf Request for testing extractors without a router.

Exceptions / Errors

TestAssertionError
Extends Error so package:test treats it as a test failure without depending on package:test.