I'm writing integration tests for Controller classes in my .NET Core WebAPI, and honestly, I'm not sure if Assert.Equal(HttpStatusCode.OK, response.StatusCode); is enough. I'm using my production Startup class with only database different (using InMemory database).
This is one of my tests, named ShouldAddUpdateAndDeleteUser. It's basically:
- Send
POSTrequest with specific input. - Assert If
POSTworked. BecausePOSTsends respond with created object, I canAsserton every property and if theIdis greater then 0. - Change the output a little bit and send
Updaterequest - Send
GETrequest and assert if update worked. - Send
DELETErequest - Send
GETrequest and assert if null.
Basically, I test, ADD,UPDATE,DELETE,GET (when item exists), GET (when item doesn't exists).
I have a few questions:
- Is it a good practice to have such tests? It does do a lot, but it's not a unit test after all. If it fails, I can be pretty specific and specify which part didn't work. Worst case scenario I can debug it pretty quickly.
- Is it integration tests or functional test or neither?
- If this is wrong, how can I test
DELETEorUPDATE? I'm kinda forced to callGETrequest after them (They returnNoContent)
(Side note: It's not the only test I have for that controller obviously. I also have tests for GET all as well as BedRequest requests)
Aucun commentaire:
Enregistrer un commentaire