Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy native libraries to the unit test staging directory in Visual Studio 2010

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 :).

like image 849
Kiril Avatar asked Mar 20 '12 19:03

Kiril


2 Answers

Solution wide deployment

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.

enable deployment

Single method deployment

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");
}
like image 183
KMoraz Avatar answered Nov 11 '22 12:11

KMoraz


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

like image 45
MStodd Avatar answered Nov 11 '22 13:11

MStodd