Assertions

SoapUI supports a rich set of assertions to validate responses.

Common assertions

text
Right-click a request step → Add Assertion

Response Status → Valid HTTP Status Codes → 200,201
Response Contains → "success": true
Response Does Not Contain → "error"
JSONPath Match → $.data[0].name = Alice
XPath Match → //user/name = "Alice"
Script Assertion (Groovy) → custom validation
Response SLA → max response time: 2000ms

JSONPath assertion

text
Assertion type: JSONPath Match
JSONPath: $.users[0].email
Expected: [email protected]

// Multiple assertions per step
$.users.length() = 10
$.status = "active"

Script assertion (Groovy)

groovy
// Groovy script assertion
def response = messageExchange.response.responseContent
def json = new groovy.json.JsonSlurper().parseText(response)

assert json.status == "success", "Expected status 'success' but got: ${json.status}"
assert json.data.size() > 0, "Expected non-empty data array"
assert json.data[0].email?.contains("@"), "Expected valid email"

log.info "Assertions passed for response: ${json}"