I have a number of test classes and methods that copy a particular directory like so:
[TestClass, DeploymentItem("LanguageData", "LanguageData")]
public class OcrTests
{
[TestMethod]
public void Can_Capture_Field()
{
// some code that expects the LanguageData directory to be in the test results Out directory
}
// etc
}
[TestClass]
public class OcrBuilderTests
{
[TestMethod, DeploymentItem("LanguageData", "LanguageData")]
public void Can_Build_Specific_Ocr_Engine_Implementation()
{
// some more code that expects the LanguageData directory to be in the test results Out directory
}
// etc
}
Those tests are in a single assembly and all the files in the LangaugeData directory have their Copy to Output Directory
set to Copy Always
.
It all works fine and the directory is copied to the test results Out
directory as long as I only have that one test assembly loaded into the solution or that's the only assembly I run tests from (i.e. run tests only in current context/class).
As soon as I add a second assembly and run all the tests in the solution then that directory no longer gets copied, but any other DeploymentItems that are just individual files seem to get copied fine.
The tests themselves all still run, but the ones that depend on that directory crash. Presumably that's because MSTest can't find the directory - perhaps it's expecting it to be in the build directory of one of the other test assemblies?
Any ideas what it is about multiple test projects that's preventing the copy, and what I can do to get around it, short of adding every single file in that directory as an individual DeploymentItem?
This question is quite old, but could still benefit others. Especially since I ended up here :)
It seems that
DeploymentItemAttribute
doesn't support using the same source path name in multiple test classes. Note: I said same path name, not physical folder (think different test projects with same folder name to deploy).However the destination folder name can be different, with no ill effects.
My suggestion is:
[TestClass, DeploymentItem("LanguageData", "LanguageData")]
OcrTests
andOcrBuilderTests
classes to inherit the new class.I've tried this, with Great Success. In my case, I had a common test fixture project and multiple test projects, each using the base class.
Unfortunately the DeploymentItemAttribute is filled with Gotchas, see here for more.