How should I unit-test a simple CRUD-class?

前端 未结 2 1132
误落风尘
误落风尘 2021-02-04 18:28

I am right now trying to do very, very simple stuff with unit-testing in VS2008, to get started and get a feel for this. I think I have testing of small non-database stuff down,

2条回答
  •  野的像风
    2021-02-04 19:08

    I find that it works best to do basically what you've outlined. However, rather than splitting the create event up into each operation, I tend to create a single record in one method but store the id value of that record in a private class variable, then I fetch it back (read) inside of each method. So, then I have a Read assert method, then another Update assert method, and finally a Delete assert method.

    Though, what you've outlined above is very thorough. The biggest problem though, is if your delete method fails in your read assert method, then you could be mislead into believing that your read functionality is broken when in fact it is the delete functionality is deleted.

提交回复
热议问题