TestResponse
All TestClient methods return a TestResponse. The object contains the raw status, headers, and body as well as a lazily-parsed JSON representation when the content-type header contains application/json.
final response = await client.getJson('/users/1');
response
.assertSuccess()
.assertHeaderContains('content-type', 'application/json')
.assertJsonPath('id', 1);
Status Assertions
assertStatus(int expected)assertSuccess()— 200 ≤ status < 300assertClientError()— 400 ≤ status < 500assertServerError()— 500 ≤ status < 600
Header Helpers
assertHasHeaders()/assertNoHeaders()assertHasHeader(String key)assertHeader(String key, String value)— equality matchassertHeaderContains(String key, dynamic value)— substring or collection containsassertContentType(String mime)— shorthand for the common caseheader(String key)— retrieve the raw header list (also triggersassertHasHeader)cookie(String name)— retrieve a parsed cookie fromset-cookie
Body Assertions
assertBody(String expected)andassertBodyEquals(String expected)assertBodyContains(String substring)assertBodyIsEmpty()/assertBodyIsNotEmpty()assertNoBody()when an empty response is expected
JSON Utilities
json()returns the decoded payload (throws if content-type is not JSON)json(path)drills into dot-delimited keys ('user.profile.name')assertJsonPath(String path, dynamic expected)assertJson(AssertableJsonCallback callback)leverages theassertable_jsonDSL (json.has('items').count('items', 2))assertJsonContains(Map<String, dynamic> partial)for partial map comparisonsassertJsonFilesContain(String key, String filename)convenience helper for list-of-files structures
assertJsonand the fluent DSL ship from theassertable_jsonpackage, whichserver_testingre-exports for convenience. Importingpackage:server_testing/server_testing.dartgives you the assertion API without adding another dependency.
Debugging Helpers
dump()prints the URI, status line, headers, and body in an HTTP-like format—handy when a test fails unexpectedly.
Because the assertions return this, they are chainable. Combine them to keep tests readable:
final login = await client.postJson('/login', {
'email': 'a@b.test',
'password': 'secret',
});
login
..assertStatus(200)
..assertJsonContains({'token': 'abc123'});