I'm trying to write some tests for a web application based on HTTP REST API. I used to verify the contents uploaded through a POST request with a GET request. But I realized that I've tested a request using other requests. In other words, my tests depended on each other in most cases. Because of this situation, whenever I changed an API spec, I often had to change all the tests indirectly affected.
For example,
testGetA() =>
expect(app.get('/A')).to.have.json('this', '{"foo":"bar"}')
testPostA() => {
expect(app.delete('/A')).to.have.status(200)
expect(app.post('/A', '{"foo":"bar"}')).to.have.status(200)
expect(app.get('/A')).to.have.json('this', '{"foo":"bar"}')
}
testPostA uses DELETE, POST, and GET sequentially to test posting resource A. But if I change the spec of GET /A so that GET /A responds with {"foo":"barzoo"}, I must change not only testGetA but also testPostA.
Aucun commentaire:
Enregistrer un commentaire