Search code examples
visual-studiomstest

How do I make a data file available to unit tests?


I'm using VS2008 TFS (with MSTest).

I have a unit test that works reliably, relying on a data file in a subfolder of the project (ie testproject1\TestData). The data file properties are Build Action=Content, Copy Always. (It is not a test datafile as such, but a file that the production code reads and normally expects in its own folder)

When the test is built and executes, the data file is correctly copied to the ...\TestResults\(testruniD)\Out folder, and the tested code finds it.

Now, I move the test and its data file to another test project in the solution (where it really should be), The data file is in the same folder relative to the new test project (testproject2\TestData), and the data file properties are checked as still being as above. However on rebuild the test fails in the new location because the data file has not been copied to the test results output folder so the executing code cannot find it.

Is there something extra I should have done to ensure the data file is still copied?

I've had a related problem before, whereby some data files are copied to the test results output folder and some are not, for no apparent reason, and it bewilders me.

TIA


Solution

  • Use the DeploymentItem attribute (more info here).

    Edit: As per the OP, the .testrunconfig file must also be edited.