given · when · then
Test REST services in Java the way you would describe them.
REST Assured sends the request and checks the response in one readable chain. JSON and XML paths, status, headers, cookies, authentication and Spring MockMvc, with no HTTP plumbing in your tests.
when(). get("/lotto/{id}", 5). then(). statusCode(200). body("lotto.lottoId", equalTo(5), "lotto.winners.winnerId", hasItems(23, 54));
{
"lotto": {
"lottoId": 5, ✓
"winning-numbers": [2, 45, 34, 23, 7, 5, 3],
"winners": [
{ "winnerId": 23, "numbers": [2, 45, 34, 23, 3, 5] }, ✓
{ "winnerId": 54, "numbers": [52, 3, 12, 11, 18, 22] } ✓
]
}
}Documentation
Build the request
Parameters, headers, cookies, bodies from your own objects, multi-part uploads, and basic, digest, form, OAuth or CSRF authentication.
thenCheck what came back
GPath or Jayway JSONPath on JSON, GPath and XPath on XML, JSON Schema validation, response time, and logging when a check fails.
withYour stack
Spring MockMvc and WebTestClient without a server, Kotlin and Scala extensions, the JDK HTTP client or Apache HttpClient 5.
Add it to your build
Pick what your tests do and copy the dependencies. The BOM keeps every REST Assured module on the same version.
Which module do I need explains each one.
News
All news- REST Assured 7.0.0-RC1
It's the release candidate for 7.0.0, a new major release. REST Assured now sends requests with the JDK's HTTP client by default, with Apache HttpClient 5 in the new http-client-apache5 module, and no longer depends on Groovy.
- REST Assured 6.3.0
It prepares for REST Assured 7.0.0, which drops Apache HttpClient 4 and Groovy from the default dependencies. Every API that 7.0.0 removes now has a replacement, the old ones are deprecated, and the new rest-assured-openrewrite module has a recipe that moves your code over.
- REST Assured 6.2.0
The rest-assured module is now written entirely in Java and no longer depends on Groovy directly. Tests that run in parallel no longer fail because of races in the static configuration, and auth().certificate(..) now sends the client certificate to servers that ask for one (mutual TLS).
Who
REST Assured is developed and maintained by Johan Haleby with the help of many contributors. Johan started the project at Jayway in December 2010. It is now sponsored by Parkster.
Want to help? Open a pull request or an issue.