NUnit [TearDown] fails — what process is accessing my files?

前端 未结 11 2557
你的背包
你的背包 2021-02-12 14:17

Final Edit: I found a solution to the problem (at the bottom of the question).

I\'ve got an Nunit problem that\'s causing me grief. Edit:

11条回答
  •  日久生厌
    2021-02-12 15:05

    I'd need to see your filename creation logic, but it is possible that you are opening the file to create it but not closing it once it is created. I think if you use System.IO.Path.GetTempFileName() it will just create the file and return you the name of the file with the file closed. If you are doing your own random name generation and using File.Open, you'll need to make sure it's closed afterwards.

    On another note, I heartily recommend pursuing a mocking strategy to abstract out the database rather than reading/writing from an actual database in your unit tests. The point of unit tests is that they should be very fast and file I/O is going to really slow these down.

提交回复
热议问题