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
POST
request with specific input. - Assert If
POST
worked. BecausePOST
sends respond with created object, I canAssert
on every property and if theId
is greater then 0. - Change the output a little bit and send
Update
request - Send
GET
request and assert if update worked. - Send
DELETE
request - Send
GET
request 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
DELETE
orUPDATE
? I'm kinda forced to callGET
request 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