Unit test: cannot delete a copied file

Yu Hou 1 Reputation point
2022-10-20T21:09:28.203+00:00

hi, I am writing an unit test to test a very simple application. The application is very simple. It only have two public APIs:

  1. OpenFile API: copy an existing binary file to a new created temp file and read it.
  2. CloseFile API: close both files and delete the temp file created in OpenFile API.

While running/debugging the application, both APIs work fine. CloseFile API can delete the temp file without any issue. While I created an Unit test project to try to test the application's two APIs. In my test case, I just call both APIs 100 times (repeat open file and close file). But while calling CloseFile API, it always throw exceptions at the point deleting temp file by saying the file is being opened by other program. To test it further, I wrote another console app to call the two APIs 100 time (same logic as unit test). No issue at all.

Do you know why?

Thanks,
Yu

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
351 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.