routed_testing library
Integration between the Routed framework and the server_testing package.
This library provides utilities for testing Routed applications using the server_testing package's fluent testing API.
Example
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() {
// Create a Routed engine with routes
final engine = Engine()
..get('/hello', (req, res) => res.send('Hello, World!'))
..get('/users', (req, res) => res.json({
'users': [{'name': 'Alice'}, {'name': 'Bob'}]
}));
// Create the handler
final handler = RoutedRequestHandler(engine);
// Test with server_testing
engineTest('GET /users returns user list', (client) async {
final response = await client.get('/users');
response
.assertStatus(200)
.assertJson((json) {
json.has('users').count('users', 2);
});
}, handler: handler);
}
Classes
- RoutedRequestHandler
- Adapter for the Routed Engine that conforms to the RequestHandler interface.
Functions
-
engineGroup(
String description, {Engine? engine, required void define(Engine engine, TestClient client, EngineTestFunction ), TransportMode transportMode = TransportMode.inMemory, Map< String, dynamic> ? configItems, EngineConfig? engineConfig, List<EngineOpt> ? options, List<ServiceProvider> ? providers}) → void - Creates a group of tests with shared engine configuration
-
engineTest(
String description, TestCallback callback, {Engine? engine, TransportMode transportMode = TransportMode.inMemory, Map< String, dynamic> ? configItems, EngineConfig? engineConfig, List<EngineOpt> ? options, List<ServiceProvider> ? providers, bool autoCloseEngine = false}) → void -
Defines a single test that runs with a dedicated
EngineandTestClient.
Typedefs
- EngineTestFunction = void Function(String description, TestCallback callback)
-
A callback function used by the
engineGrouphelper to define tests within the group. It receives the sharedEngineandTestClientinstances, and a function (engineTest) which should be used to define individual tests within the group. -
TestCallback
= Future<
void> Function(Engine engine, TestClient client) -
A callback function used by the
engineTesthelper. It receives theEngineandTestClientinstances for the test.