Unit Test in Visual Studio Fails to Copy a Critical Configuration File which Fails Test

I ran into this problem when working with Visual Studio 2010. I had a project which had a SQL Server Compact database file (.sdf) which according to the build was to be Copied to the output directory during builds. But the problem was that during my unit testing, this file was not being copied out to the target directory for unit testing and code coverage. Once the test was run, it would fail because the database file could not be found.


To have any ancillary file included in a test output run, one needs to add it to the test deployment.  Here are the steps

  1. In the Solution Items folder of the solution find Local.testsettings file.
  2. Double click the Local.testsettings file
  3. Select the Deployment category.
  4. Choose the file by selecting the Add File button.
  5. Path to the file.

Done and retest to verify.


Leave a Reply