Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net unit testing - How to test Insert/Update/Delete methods

I am using .net unit testing in my project. I can unit test, get methods by using Assert.AreEqual. But how can i test Insert/update/delete methods. Please help

Thanks in advance.

like image 751
Sidharth Avatar asked Mar 07 '11 09:03

Sidharth


People also ask

Is it good practice to make all methods public?

Yes it is very bad practice - you're letting your tools make design decisions for you. I think the main problem here is that you're trying to treat each individual method as a unit. This is generally the cause of all unit test woes.


1 Answers

For insert, the basic test pattern could be:

  • create entity instance
  • insert entity
  • read inserted entity
  • compare created entity and read entity
  • delete entity

For update:

  • create entity instance
  • insert entity
  • change entity properties
  • update entity
  • read updated entity
  • compare changed entity and read entity
  • delete entity

For delete:

  • create entity instance
  • insert entity
  • delete entity
  • read deleted entity (should fail)

Note than in order to compare reference entities, you can do it manually for each entity type or use a recursive entity comparison method

like image 106
vc 74 Avatar answered Nov 15 '22 08:11

vc 74