Example

We have an app that exposes create , read , update , and delete operations for customer records. Records are being served under /customers .Here is an example of a CRUD operations test. Groovy package scenarios.rest.springboot import static org.testingisdocumenting.webtau.WebTauGroovyDsl.* scenario("CRUD operations for customer") { def customerPayload = [firstName: "FN", lastName: "LN"] // new customer data def id = http.post("/customers", customerPayload) { return id // return id value from response body } http.get("/customers/${id}") { body.should == customerPayload // only specified properties will be asserted against } def changedLastName = "NLN" http.put("/customers/${id}", [*:customerPayload, lastName: changedLastName]) { lastName.should == changedLastName // specifying body is optional } http.get("/customers/${id}") { firstName.should == "FN" lastName.should == changedLastName } def changedFirstName = "NFN" http.patch("/customers/${id}", [firstName: changedFirstName]) http.get("/customers/${id}") { firstName.should == changedFirstName lastName.should == changedLastName } http.delete("/customers/${id}") { statusCode.should == 204 } http.get("/customers/${id}") { statusCode.should == 404 } } Java package com.example.tests.junit5; import org.testingisdocumenting.webtau.junit5.WebTau; import org.junit.jupiter.api.Test; import java.util.Map; import static org.testingisdocumenting.webtau.WebTauDsl.*; @WebTau public class CustomerCrudJavaTest { @Test public void crud() { Map<String, ?> customerPayload = aMapOf( // new customer data "firstName", "FN", "lastName", "LN" ); int id = http.post("/customers", customerPayload, ((header, body) -> { return body.get("id"); // return id value from response body })); http.get("/customers/" + id, ((header, body) -> { body.should(equal(customerPayload)); // only specified properties will be asserted against })); String changedLastName = "NLN"; Map<String, ?> changedCustomerPayload = aMapOf( "firstName", "FN", "lastName", changedLastName); http.put("/customers/" + id, changedCustomerPayload, ((header, body) -> { body.get("firstName").should(equal("FN")); body.get("lastName").should(equal(changedLastName)); })); http.get("/customers/" + id, ((header, body) -> { body.should(equal(changedCustomerPayload)); })); http.delete("/customers/" + id, ((header, body) -> { header.statusCode().should(equal(204)); })); http.get("/customers/" + id, ((header, body) -> { header.statusCode().should(equal(404)); })); } }

Implicit statusCode Check

If you don't have an explicit statusCode validation it will be automatically validated based on the rules below Method Expected Code [{text=GET, type=SimpleText}] [{text=200, type=SimpleText}] [{text=POST, type=SimpleText}] [{text=201, type=SimpleText}] [{text=PUT, type=SimpleText}] [{text=200, type=SimpleText}] [{text=PUT (no content), type=SimpleText}] [{text=204, type=SimpleText}] [{text=DELETE, type=SimpleText}] [{text=200, type=SimpleText}] [{text=DELETE (no content), type=SimpleText}] [{text=204, type=SimpleText}] [{text=PATCH, type=SimpleText}] [{text=200, type=SimpleText}] [{text=PATCH (no content), type=SimpleText}] [{text=204, type=SimpleText}]

Report

After your test executions a report will be produced.Note: asserted values are being tracked and highlighted inside the report