Reputation: 793
I am using the built-in unit testing framework of Visual Studio 2008 to get my feet wet with TDD of a C# WinForms application. The application works with proprietary image data formats and I've broken up sample files into their component sections (header, metadata, single frames, all frames, etc) to allow for testing. Several of my test methods use the same data chunk and when I choose the 'Run All Tests in Solution' option, the tests using the same data chunk fail with "System.IO.IOException: The process cannot access the file 'datachunk.dat' because it is being used by another process." These tests pass when they are run individually. Is there a way I can tell Visual Studio not to try and run these tests at the same time or am I going about this the wrong way?
Upvotes: 1
Views: 297
Reputation: 8916
I can suggest several things:
Upvotes: 0
Reputation: 17010
Use the intialize method to load the "chunk" before the tests need it. You can then reuse the same "chunk" over and over, across tests.
You can also encapsulate the logic into its own method and ensure you destroy the reader between hits on the method.
Peace and Grace, Gregory A. Beamer
Upvotes: 1
Reputation: 498914
Read it once in a TestInitialize
function, reading into a field, so it is available to all the tests in the class.
Upvotes: 0