Skip to content
CodeKruPro

Reusable request and response specifications

Automation taskMediumJava only

"How do you avoid repeating the base URI and headers in every test?" The answer is RequestSpecBuilder and ResponseSpecBuilder, which build specifications: saved sets of settings and checks that every test can reuse. You practise them in this lesson.

Combined Request and Response Specs

Combined Request and Response Specs

In real frameworks, you combine both request and response specs for clean, DRY tests:

given().spec(reqSpec).get(path).then().spec(resSpec).body(...);

Task: Create both specs and use them together to validate and extract user 1's name.

Expected output:

Validated and extracted: John Doe