Unit test insert/update/delete
- by Kurresmack
Hey,
I have googled this a little and didn't really find the answer I needed.
I am working on a webpage in C# with MSSQL and LINQ for a customer.
I want the users to be able to send messages to each other. So what I do is that I unit test this with data that actually goes into the database.
The problem is that I now depend on having at least 2 users who I know the ID of. Furthermore I have to clean up after my self. This leads to rather large unit tests that test alot in one test.
Lets say I would like to update a user. That would mean that I would have to ceate the user, update it, and then delete it. This a lot of assertions in one unit test and if it fails with updating i have to manually delete it.
If I would do it any other way, without saving the data to DB, I would not for sure be able to know that the data was present in the database after updating etc.
What is the proper way to do this without having a test that tests a lot of functuality in one test?