routed_testing 0.2.1+1
routed_testing: ^0.2.1+1 copied to clipboard
Routed-specific testing utilities that extend server_testing for integration tests.
routed_testing #
Routed-specific helpers built on top of server_testing. It wires the Routed
engine into the transport abstractions so you can issue HTTP requests against an
in-memory engine or launch an ephemeral server without writing glue code.
Features #
- Drop-in RequestHandler –
RoutedRequestHandlerbootstraps anEngineand connects it to the testing transports. - In-memory & real sockets – flip between
TransportMode.inMemoryandTransportMode.ephemeralServerwithout changing your test body. - Property helpers – reuse
TestClientwithproperty_testingto stress routing, params, or middleware stacks.
Install #
dev_dependencies:
routed_testing: ^0.2.1
server_testing: ^0.2.0
routed: ^0.2.0
test: ^1.26.0
dart pub add --dev routed_testing server_testing routedwill update your pubspec automatically.
Usage #
import 'dart:io';
import 'package:routed/routed.dart';
import 'package:routed_testing/routed_testing.dart';
import 'package:server_testing/server_testing.dart';
import 'package:test/test.dart';
void main() {
test('GET /ping', () async {
final engine = Engine()..get('/ping', (ctx) => ctx.text('pong'));
await engine.initialize();
final handler = RoutedRequestHandler(engine);
final client = TestClient.inMemory(handler);
final response = await client.get('/ping');
response.assertStatus(HttpStatus.ok).assertBodyContains('pong');
await client.close();
await handler.close();
await engine.close();
});
}
See test/ for more patterns, including property-based coverage of route
parameters across transports.
Funding #
Help sustain the Routed ecosystem by sponsoring @kingwill101.***