DoxTestClient class
Sends requests to your app in tests.
start runs the app in the test, on 127.0.0.1 and a free port the OS
picks. So many test files can run at the same time.
late DoxTestClient client;
setUpAll(() async {
client = await DoxTestClient.start(appConfig);
});
tearDownAll(() async {
await client.close();
});
test('ping', () async {
TestResponse res = await client.get('/api/ping');
res.expectStatus(200).expectBody('pong');
});
Constructors
-
DoxTestClient(Uri baseUri, {Map<
String, String> ? headers}) -
a client for a server that already runs at
baseUri
Properties
- baseUri → Uri
-
the url of the server, eg.
http://127.0.0.1:53211final - hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, String> -
headers sent with every request of this client
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> -
Stop the server of start (and its
DoxShutdownservices), and close this client. -
delete(
String path, {Object? body, Map< String, String> ? headers}) → Future<TestResponse> -
get(
String path, {Map< String, String> ? headers}) → Future<TestResponse> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
patch(
String path, {Object? body, Map< String, String> ? headers}) → Future<TestResponse> -
post(
String path, {Object? body, Map< String, String> ? headers}) → Future<TestResponse> -
put(
String path, {Object? body, Map< String, String> ? headers}) → Future<TestResponse> -
send(
String method, String path, {Object? body, Map< String, String> ? headers}) → Future<TestResponse> -
Send a request.
pathcan have a query, eg./users?page=2. -
toString(
) → String -
A string representation of this object.
inherited
-
withCookies(
Map< String, String> values) → DoxTestClient -
a copy of this client that sends
valuesas cookies. Use thecookiesof a response to go on with its session. -
withHeaders(
Map< String, String> values) → DoxTestClient -
a copy of this client that also sends
valueswith every request -
withToken(
String token) → DoxTestClient -
a copy of this client that sends
Authorization: Bearer <token>.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
start(
AppConfig config) → Future< DoxTestClient> -
Start the app of
configin this isolate and give a client for it.