Question

I have written a unit test that uses a CSV file to read in data using the "DataSource" and "DeploymentItem" Attributes pointing to a csv file in a subfolder. However, when initially building the project the files are deployed in two different locations, one in the root and the other in the subfolder. When I then later change the CSV file with different data and save and re-build the project (having the CSV property "Copy to Output" set to "Copy always", just to make sure), it copies the changes to the correct output subfolder but not the root. This is what I would expect but the problem is, that when running the tests, it still reads in old data because it picks the CSV file up from the root and not the subfolder. So each time I have to go to the output folder and copy the CSV file from the subfolder into the root folder for the test to pick up the changes.

Does anybody know how to fix this so the test looks in the subfolder to pick up the CSV file and not the root?

[TestMethod()]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"|DataDirectory|\\Data\MyData.csv", "MyData#csv", DataAccessMethod.Sequential)]
[DeploymentItem("MyApp\\MyTest\\MyTests.Tests\\Data\\MyData.csv")]  
Was it helpful?

Solution

You can add a TestSettings.settings file to your solution by selecting the solution and then clicking New... and then selecting TestSettings. if you double click that fie it will give you a dialog with some options, one of those is Deployment. If you enable that, you can add files and directories that get deployed to your test running directory.

This link explains it a bit better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top