I have a situation where I want to create some data using a post
request and then use the result of that post in few other tests, is it possible to do this using spock. From the below I would like to reuse the response
(or something thats extracted from it. How can I do that?
def "AddAssessment valid output case"() {
given:
def request = """
{
"assessmentTopic" : "$assessmentTopic",
"assessmentSubTopic" : "$assessmentSubTopic",
"duration" : "$duration",
"assessmentLevel" : "$assessmentLevel"
}
"""
when:
def result = mvc.perform(
MockMvcRequestBuilders
.post("/assessments/createAssessment")
.content(request)
.contentType(MediaType.APPLICATION_JSON)
)
then:
MvcResult response = result
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath('$.*').doesNotExist())
.andReturn()
where:
assessmentTopic | assessmentSubTopic | duration | assessmentLevel
"Maths" | "Calculus" | "120" | "1"
"Civils" | "History" | "500" | "4"
"UPSC" | "GK" | "120" | "5"
"Chemistry" | "Elements" | "120" | "3"
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…