I've been browsing through stackoverflow reading other questions about MSTest and DeploymentItem; I've followed all the advice, but nothing has worked for me. I have a folder called "ImportFiles" in my test project with a file called "contacts.xlsx" which has the property Copy to Output Directory set to Copy always, but the file is not getting copied when I run the test.
Sample code below. Any ideas?
[TestMethod]
[DeploymentItem(@"ImportFiles/contacts.xlsx")]
public void MyTestName()
{
// get the file and use it here
var extensions = new {"xlsx"};
var d = new DirectoryInfo(this.TestContext.TestDeploymentDir);
List<FileInfo> importFiles = d.GetFiles().Where(f => extensions.Any(e => f.Extension.EndsWith(e))).ToList();
}
I've also been monitoring the directories as the test is initializing. Nothing but the dlls config and pdb files are getting copied.
What I found out is this:
I use Resharper and often run tests with Resharper controls. Resharper v6 does not properly initialize MSTest with DeploymentItems, i.e. the DeploymentItems are never copied to the output directory. The solution is to not use Resharper commands to run tests. If you use the VS 2010 commands for Test or Debug (or use Ctrl R,T) from the Test menu, everything is deployed properly and the tests will run.