Replies: 1 comment 1 reply
-
That's exactly what Data Driven Testing is for. Something like this: def "Keywords (green)"() {
expect:
def jsonResponse = restClient.getResponse("""{
"q": "${keyword}",
}""")
def jsonString = testHelper.getJsonData("green",keyword)
def testData = new JsonSlurper().parseText(jsonString)
with(jsonResponse) {
results[0].matchingDocumentCount == testData.results[0].matchingDocumentCount
results[0].hits.length == testData.results[0].hits.length
testData.results[0].hits.eachWithIndex { item, index ->
assert results[0].hits[index].title == item.title
assert results[0].hits[index] == item
}
}
where:
keyword << testHelper.getKeywords("green")
}
Be aware that I changed some more details:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Folks;
pretty new to using Spock for testing (and maybe having a disputable use case here), looking for some insights and hints on a more architectural level. Simply put: I need to test a REST/JSON API and make sure certain requests consistently provide the same responses. For that purpose, I do have a list of parameters (essentially keywords provided to a particular endpoint) and the JSON structure the API is supposed to return for these keywords. What I need / want to do is writing a test case which iterates this keyword list, sends the appropriate requests to the API, compares with whatever the API returns to the predefined JSON stored locally and reports which of these queries failed.
At the moment, I'm handling it more or less like this (in Groovy)...
`
def "Keywords (green)"() {
... which generally works but has the big drawback that, currently, it's all-or-nothing - this test case will fail the very moment it encounters the first keyword for which this test fails. So I guess I need a better implementation. Any recommendations on what to look into / where to start reading to improve this?
Thanks very much for any pointers, best regards,
Kristian
Beta Was this translation helpful? Give feedback.
All reactions