QA REST Assured Writer
Purpose
Write REST Assured API tests from test cases and API contracts. Transform structured test cases (from qa-testcase-from-docs, qa-api-contract-curator, OpenAPI specs) into executable REST Assured test files with BDD-style syntax, JSON/XML schema validation, authentication handling, and Allure reporting.
Trigger Phrases
- "Write REST Assured tests for [API/endpoint]"
- "Generate REST Assured API tests from OpenAPI"
- "Create REST Assured tests with schema validation"
- "Add REST Assured tests for [resource]"
- "REST Assured BDD-style API tests"
- "REST Assured tests with Bearer auth"
- "REST Assured JSON schema validation"
- "API tests with given/when/then"
- "Heal my failing REST Assured tests"
Key Features
| Feature |
Description |
| BDD-style |
given().when().then() fluent API for readable tests |
| JSON schema |
JsonSchemaValidator for response schema validation |
| XML schema |
XML schema validation support |
| Authentication |
Basic, Bearer, OAuth2, custom headers |
| Request/Response spec |
RequestSpecification, ResponseSpecification for reuse |
| Serialization |
Jackson/Gson for POJO serialization/deserialization |
| Extraction |
extract().response(), path(), jsonPath() for assertions |
| Allure |
@Step, @Description, @Severity for reporting |
Workflow
- Read test cases / API contract — From specs, OpenAPI, or manual test designs
- Analyze API — Endpoints, request/response schemas, auth requirements
- Generate test classes — Produce
{Resource}ApiTest.java with BDD structure
- Configure base URI and specs — RequestSpecification for common setup
- Add validation — Status codes, body assertions, schema validation
- Run — User runs
mvn test to execute tests
Key Patterns
| Pattern |
Usage |
given().header().body().when().post().then().statusCode(201) |
Basic request/response |
given().auth().oauth2(token) |
Bearer token auth |
given().auth().basic(user, pass) |
Basic auth |
then().body(JsonSchemaValidator.matchesJsonSchema(schema)) |
JSON schema validation |
RequestSpecification |
Reusable request config (base URI, headers) |
ResponseSpecification |
Reusable response assertions |
extract().response() |
Extract response for further assertions |
extract().path("$.id") |
Extract value from JSON path |
BDD Structure
@Test
@DisplayName("Create user returns 201")
void createUser_returns201() {
given()
.contentType(ContentType.JSON)
.body(userRequest)
.when()
.post("/users")
.then()
.statusCode(201)
.body("id", notNullValue())
.body("email", equalTo("user@example.com"));
}
File Naming
{Resource}ApiTest.java — Test classes (e.g., UserApiTest.java, OrderApiTest.java)
- Place in
src/test/java per Maven convention
Scope
Can do (autonomous):
- Generate REST Assured API tests from test case specs or OpenAPI
- Apply BDD-style given/when/then structure
- Add JSON/XML schema validation
- Configure authentication (Basic, Bearer, OAuth2)
- Use RequestSpecification/ResponseSpecification for reuse
- Add Allure annotations for reporting
- Use Context7 MCP for REST Assured docs
- Delegate to qa-test-healer when tests fail (Heal Mode)
Cannot do (requires confirmation):
- Change production code structure
- Add dependencies not in pom.xml
- Override project REST Assured config without approval
- Call APIs not provided or approved
Will not do (out of scope):
- Execute tests (user runs
mvn test)
- Write Selenium/Playwright tests (use qa-selenium-java-writer, qa-playwright-ts-writer)
- Modify CI/CD pipelines
- Bypass security or access restricted APIs
References
references/patterns.md — CRUD, auth, validation, filters, serialization
references/config.md — Maven config, base URI, logging
references/best-practices.md — API testing best practices with REST Assured
Quality Checklist
Troubleshooting
| Symptom |
Likely Cause |
Fix |
| Connection refused |
Wrong base URI, service not running |
Verify baseUri; ensure API is up |
| 401/403 |
Missing or invalid auth |
Add auth to given(); check token expiry |
| Schema validation fails |
Schema mismatch, wrong path |
Verify schema file; check JSON path |
| Body assertion fails |
Wrong JSON path, type mismatch |
Use jsonPath() to debug; ensure correct type |
| Timeout |
Slow API, network |
Increase timeout in config |
| Serialization error |
POJO mismatch |
Verify POJO fields match JSON; check annotations |
1---2name: qa-rest-assured-writer3description: Generate REST Assured API tests for Java with BDD-style syntax, JSON/XML schema validation, authentication handling, and Allure reporting.4---56# QA REST Assured Writer78## Purpose910Write REST Assured API tests from test cases and API contracts. Transform structured test cases (from qa-testcase-from-docs, qa-api-contract-curator, OpenAPI specs) into executable REST Assured test files with BDD-style syntax, JSON/XML schema validation, authentication handling, and Allure reporting.1112## Trigger Phrases1314- "Write REST Assured tests for [API/endpoint]"15- "Generate REST Assured API tests from OpenAPI"16- "Create REST Assured tests with schema validation"17- "Add REST Assured tests for [resource]"18- "REST Assured BDD-style API tests"19- "REST Assured tests with Bearer auth"20- "REST Assured JSON schema validation"21- "API tests with given/when/then"22- "Heal my failing REST Assured tests"2324## Key Features2526| Feature | Description |27| ------- | ----------- |28| **BDD-style** | given().when().then() fluent API for readable tests |29| **JSON schema** | JsonSchemaValidator for response schema validation |30| **XML schema** | XML schema validation support |31| **Authentication** | Basic, Bearer, OAuth2, custom headers |32| **Request/Response spec** | RequestSpecification, ResponseSpecification for reuse |33| **Serialization** | Jackson/Gson for POJO serialization/deserialization |34| **Extraction** | extract().response(), path(), jsonPath() for assertions |35| **Allure** | @Step, @Description, @Severity for reporting |3637## Workflow38391. **Read test cases / API contract** — From specs, OpenAPI, or manual test designs402. **Analyze API** — Endpoints, request/response schemas, auth requirements413. **Generate test classes** — Produce `{Resource}ApiTest.java` with BDD structure424. **Configure base URI and specs** — RequestSpecification for common setup435. **Add validation** — Status codes, body assertions, schema validation446. **Run** — User runs `mvn test` to execute tests4546## Key Patterns4748| Pattern | Usage |49| ------- | ----- |50| `given().header().body().when().post().then().statusCode(201)` | Basic request/response |51| `given().auth().oauth2(token)` | Bearer token auth |52| `given().auth().basic(user, pass)` | Basic auth |53| `then().body(JsonSchemaValidator.matchesJsonSchema(schema))` | JSON schema validation |54| `RequestSpecification` | Reusable request config (base URI, headers) |55| `ResponseSpecification` | Reusable response assertions |56| `extract().response()` | Extract response for further assertions |57| `extract().path("$.id")` | Extract value from JSON path |5859## BDD Structure6061```java62@Test63@DisplayName("Create user returns 201")64void createUser_returns201() {65 given()66 .contentType(ContentType.JSON)67 .body(userRequest)68 .when()69 .post("/users")70 .then()71 .statusCode(201)72 .body("id", notNullValue())73 .body("email", equalTo("user@example.com"));74}75```7677## File Naming7879- `{Resource}ApiTest.java` — Test classes (e.g., `UserApiTest.java`, `OrderApiTest.java`)80- Place in `src/test/java` per Maven convention8182## Scope8384**Can do (autonomous):**85- Generate REST Assured API tests from test case specs or OpenAPI86- Apply BDD-style given/when/then structure87- Add JSON/XML schema validation88- Configure authentication (Basic, Bearer, OAuth2)89- Use RequestSpecification/ResponseSpecification for reuse90- Add Allure annotations for reporting91- Use Context7 MCP for REST Assured docs92- Delegate to qa-test-healer when tests fail (Heal Mode)9394**Cannot do (requires confirmation):**95- Change production code structure96- Add dependencies not in pom.xml97- Override project REST Assured config without approval98- Call APIs not provided or approved99100**Will not do (out of scope):**101- Execute tests (user runs `mvn test`)102- Write Selenium/Playwright tests (use qa-selenium-java-writer, qa-playwright-ts-writer)103- Modify CI/CD pipelines104- Bypass security or access restricted APIs105106## References107108- `references/patterns.md` — CRUD, auth, validation, filters, serialization109- `references/config.md` — Maven config, base URI, logging110- `references/best-practices.md` — API testing best practices with REST Assured111112## Quality Checklist113114- [ ] BDD-style given/when/then used115- [ ] Status code assertions on every request116- [ ] Schema validation where contract exists117- [ ] No hardcoded credentials (use env vars or test config)118- [ ] RequestSpecification for shared setup119- [ ] Tests independent (no shared state)120- [ ] Allure annotations where applicable121- [ ] Traceability to test case IDs where applicable122- [ ] File naming follows `{Resource}ApiTest.java` convention123124## Troubleshooting125126| Symptom | Likely Cause | Fix |127| ------- | ------------ | --- |128| Connection refused | Wrong base URI, service not running | Verify baseUri; ensure API is up |129| 401/403 | Missing or invalid auth | Add auth to given(); check token expiry |130| Schema validation fails | Schema mismatch, wrong path | Verify schema file; check JSON path |131| Body assertion fails | Wrong JSON path, type mismatch | Use jsonPath() to debug; ensure correct type |132| Timeout | Slow API, network | Increase timeout in config |133| Serialization error | POJO mismatch | Verify POJO fields match JSON; check annotations |