Unit test insert/update/delete

前端 未结 3 1264
星月不相逢
星月不相逢 2021-01-04 21:27

I have googled this a little and didn\'t really find the answer I needed.

I am working on a webpage in C# with SQL Server and LINQ for a customer. I want the users

3条回答
  •  抹茶落季
    2021-01-04 22:13

    Unit testing databases can be a PITA due to the very nature of them (persisted storage).

    To do this right, you should always start with a blank schema. Then have your testing code load fill in the data values that have to be there. This can be as simple as just executing a sql script which contains the schema and default data.

    Once that is done, then start running your tests. Tests should encompass all of the crud operations your app will normally do.

    If any failure occurs, it's not that big a deal because, again, you should start fresh every time any how.

    Also, you want to keep that data around in case of a testing failure so that you can inspect the database state at the time the failure occurred. So, this is both a good and bad thing.

    Along these lines, the db tests should be run on it's own test database instance. This way you don't have to worry about transient issues like someone changing a db structure underneath you as the tests are progressing.

    Ultimately, database testing is a project in and of itself.

提交回复
热议问题