/rest-assured

Java DSL for easy testing of REST services

Primary LanguageJavaApache License 2.0Apache-2.0

REST Assured

Build Status Maven Central

  • Testing and validating REST services | Java -- is harder than -- | dynamic languages (Example: Ruby and Groovy)
  • REST Assured
    • allows
      • bringing the simplicity of dynamic languages -- into the -- Java
      • specifying and validating
        • parameters
        • headers
        • cookies
        • body
    • supports ANY HTTP method /
      • explicit support for POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD

News

Older News

Examples

  • make a GET request & validate the JSON or XML response

    get("/lotto").then().assertThat().body("lotto.lottoId", equalTo(5));
    get("/lotto").then().assertThat().body("lotto.winners.winnerId", hasItems(23, 54));
  • -- via -- parameters

    given().
        param("key1", "value1").
        param("key2", "value2").
    when().
        post("/somewhere").
    then().
        body(containsString("OK"));
  • -- via -- X-Path (XML only)

    given().
        params("firstName", "John", "lastName", "Doe").
    when().
        post("/greetMe").
    then().
        body(hasXPath("/greeting/firstName[text()='John']")).
  • authentication mechanisms provided

    given().auth().basic(username, password).when().get("/secured").then().statusCode(200);
  • Getting and parsing a response body

    // Example with JsonPath
    String json = get("/lotto").asString();
    List<String> winnerIds = from(json).get("lotto.winners.winnerId");
        
    // Example with XmlPath
    String xml = post("/shopping").andReturn().body().asString();
    Node category = from(xml).get("shopping.category[0]");

Documentation

Support and discussion

Join the mailing list at our Google group.

Links

Buy Me A Coffee