My project has dependencies on some native libraries (DLLs) that I normally copy via the MSBuild targets into the output directory. There is no problem when I run the application, but I am writing some unit tests in Visual Studio and every time I run the unit tests, the assemblies and executables are copied from the output directory into the staging folder: C:\path\to\MyProject\TestResults\myWorkStationName 2012-03-20 13_53_56\Out
Unfortunately the native DLLs are not copied into the staging directory and the staging directory is generated on every test run. Is there an MSbuild target that allows me to copy stuff into the staging directory?
P.S. I'm not sure if "staging directory" is the correct term, so please excuse my ignorance if it's not :).
From the VS menu: Test
> Edit Test Settings
> (settings file)
> Deployment
> check Enable deployment
and add a directory or files.
Note for one caveat in this feature: enabled deployment for existing tests won't work until Visual Studio is restarted.
Use the [DeploymentItem] attribute:
[TestMethod()]
[DeploymentItem("testFile1.txt")]
public void ConstructorTest()
{
// Create the file to deploy
Car.CarInfo();
string file = "testFile1.txt";
// Check if the created file exists in the deployment directory
Assert.IsTrue(File.Exists(file), "deployment failed: " + file +
" did not get deployed");
}
For various unit test settings, including the 'staging directory' and adding additional deployment files, go to
Test->Edit Test Settings->Local
For your specific question, in that settings window, go to 'Deployment', and you should be able to add additional files to be deployed to the directory where your unit test will be run.
I believe you can also use attributes to define deployment items right in your code:
http://msdn.microsoft.com/en-us/library/ms182475.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With