liveBook · Manning

REST Assured

As explained in Quarkus in Action

REST Assured is a Java library for testing RESTful web services through programmatic HTTP requests and response assertions.

REST Assured is a Java library for calling HTTP endpoints in tests and asserting their responses. In Quarkus tests, it provides a direct way to check a REST resource through HTTP rather than calling its methods directly. Quarkus manages the server URL used by REST Assured, so ordinary requests do not need to name the server under test. section 5.2.1

Listing 3.9 Source code for a simple test
@Test
void testHelloEndpoint() {
    given()
      .when().get("/hello")
      .then()
         .statusCode(200)
         .body(is("Hello from Quarkus REST"));
}

This test sends GET /hello, checks for HTTP status 200, and asserts the exact response body. The given–when–then chain keeps the request and expected result together. section 3.5.1

To use REST Assured in a Quarkus test:

  • Add the test-scoped io.rest-assured:rest-assured dependency to pom.xml if the project did not include generated tests and their dependencies. section 5.2.1
  • Use @QuarkusTest for the test class. When a test needs a particular endpoint's URL, combine @TestHTTPEndpoint with @TestHTTPResource to inject it. section 5.2.1

Testing a reservation

A resource test creates and submits a reservation, then checks that an ID was assigned. It chooses a start day other than today to avoid a call to the Rental service, and does not exercise the availability method, which needs the Inventory service. That keeps this test focused; the Inventory call is left for a test using a mock. section 5.2.1

For a quick feedback loop, run the application with quarkus dev and press r to run tests. A changed greeting can make an exact-body assertion fail; restore the expected response or update the test to match the intended behavior. This development-mode test is distinct from a Quarkus integration-test subclass used for native mode. section 3.5.1 section 5.2.1

How Quarkus in Action covers it

How deep it goes
Demonstrates a GET assertion and a reservation resource test, but does not detail REST Assured internals.
Examples
Uses a greeting GET request and a reservation submission that verifies an assigned ID.
What it assumes
Assumes a Java Quarkus application with REST endpoints, while showing how to add the missing Maven test dependency.
What you can do after
Apply it via REST Assured to send endpoint requests and assert expected responses in Quarkus tests.
How it connects
Connects REST endpoint testing with QuarkusTest, URL injection, continuous testing, and native-mode integration tests.

Also explained in

Compare how 2 books explain REST Assured →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.