How do I properly unit test a post request?
I am using Xunit and Nsubtitute, with EFC, and SQLite db.
11 Replies
So far I have:
But I don't really understand how to test that a new Facility was successfully added...
if your mocking the service you can't test that because its a mock which does nothing
Yeah i am mocking it. So what's the proper way to write a unit test for a post request?
look into WebApplicationFactory
Ok. For my Get is this correct tho?
looks like a completely worthless test to me
so this applies to get as well?
WebAppFactory mentions integration testing.
I think this is correct now:
yes, however most people will consider this type of testing completely worthless
When unit testing, you should only mock the external dependencies of your system under test.
So in your case,
_facilityService
is the sut
and everything else is an external dependency, even the database call.
For that matter, any test that contains some kind of I/O, network hop etc. is considered an integration test.What is
sut
? And yeah, I wanted to avoid integration testing here, which I believe this test achieves.system under test