.net - testing Insert / Update / Delete methods

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

Thanks in advance.

+6
unit-testing
source share
2 answers

For insertion, the main test template can be:

  • create an instance of the object
  • insert object
  • read pasted object
  • compare the created object and the reading object
  • delete object

To update:

  • create an instance of an object
  • insert object
  • change object properties
  • update object
  • read updated object
  • compare the modified object and the reading object
  • delete object

For removing:

  • create an instance of an object
  • insert object
  • delete object
  • reading of a remote entity (should fail)

Note that to compare reference objects, you can do this manually for each type of entity or use the method of comparing recursive entities

+10
source share

To test the insert, you insert a record from your test, then get the record in the same test, and then the user Assert.AreEqual to claim that you got what you inserted. You can use a primary / unique record key to get records in this case.

A similar update would be. You update the record from the test, then you get the updated record and claim that the values ​​you received are updated values.

To delete, you delete the record from the test, and then get the record. Here you can argue that get actually returns nothing

+2
source share

All Articles