TestContext class
Factory for creating test Context instances.
Provides convenient methods for common HTTP methods.
Example:
// Simple GET request
final ctx = TestContext.get('/users');
// POST with JSON body
final ctx = TestContext.post(
'/users',
body: {'name': 'John'},
headers: {'authorization': 'Bearer token'},
);
// Access response after handler runs
await myHandler(ctx);
expect(ctx.response.statusCode, 200);
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
create(
String method, String path, {Object? body, Map< String, String> ? headers, String remoteIp = '127.0.0.1', int? contentLength}) → Context - Creates a test context with custom method.
-
delete(
String path, {Map< String, String> ? headers, String remoteIp = '127.0.0.1'}) → Context - Creates a test context with a DELETE request.
-
get(
String path, {Map< String, String> ? headers, String remoteIp = '127.0.0.1'}) → Context - Creates a test context with a GET request.
-
head(
String path, {Map< String, String> ? headers, String remoteIp = '127.0.0.1'}) → Context - Creates a test context with a HEAD request.
-
options(
String path, {Map< String, String> ? headers, String remoteIp = '127.0.0.1'}) → Context - Creates a test context with an OPTIONS request.
-
patch(
String path, {Object? body, Map< String, String> ? headers, String remoteIp = '127.0.0.1'}) → Context - Creates a test context with a PATCH request.
-
post(
String path, {Object? body, Map< String, String> ? headers, String remoteIp = '127.0.0.1'}) → Context - Creates a test context with a POST request.
-
put(
String path, {Object? body, Map< String, String> ? headers, String remoteIp = '127.0.0.1'}) → Context - Creates a test context with a PUT request.