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:53211
final
cookies → Map<String, String>
the cookies this client keeps (name to raw value). Empty when it is not a withSession client. You can change them.
no setter
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 DoxShutdown services), 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. path can 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 values as cookies. Use the cookies of a response to go on with its session.
withHeaders(Map<String, String> values) → DoxTestClient
a copy of this client that also sends values with every request
withSession() → DoxTestClient
A copy of this client that works like a browser with a session:
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 config in this isolate and give a client for it.