I am writing some unit tests and I need to be able to access an external file. I assumed I could just place the file in my solution, mark it to be copied to the output directory, and then access it via a relative path. Unfortunately, it seems that unit tests are run in a strange directory.
So, instead of running from:
[MyUnitTestProjectFolder]\bin\Release
it runs from:
[MySolution]\\[TheProjectI'mTesting]\TestResults\\[MyUsername]_[MyComputerName] [DateTimeStamp]\Out
My question is, how do I set up access to external files I need to utilize from my unit tests?
Note, the files aren't text files. They are a proprietary flat-file database format (created from another application), so preparing these files "on the fly" during the test run is not feasible.
You can do this via test run configurations: Open the Test menu, "Edit Test Run Configurations", choose a test configuration to edit, and select the "Deployment" view. Here you can add any extra files that need to be deployed.
Alternatively, you can use the DeploymentItem attribute on your tests.
I've looked at visual studio 2008, but I assume the same features exists in visual studio 2010.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With