12

I'm working on an application and I have created a number of unit tests for it. The project with the test class depends upon 3 third party DLLs. When I go to the bin\Debug folder for the test project, the Dlls are there. But when I run the test, the DLLs are not being copied into the TestResult\\Out folder.

There is also a log4net.config file from another project that I would like to have copied. This one is not showing up in the test project's bin\Debug folder, so that's another issue I have to fix.

How do I get these files to copy when I run the unit test?

Tony

vcsjones
  • 138,677
  • 31
  • 291
  • 286
Tony Vitabile
  • 8,298
  • 15
  • 67
  • 123

5 Answers5

12

You can use a DeploymentItemAttribute to copy files to the bin (or other) directory.

[TestMethod()]
[DeploymentItem("log4net.config")]
public void SomeTest()
{
   ...
}
BurnWithLife
  • 364
  • 4
  • 11
5

We have a bin folder containing 3rd-party DLL's that have to be part of builds. They are flagged with the 'copy local' attribute in the reference.

As for individual files, you can do the same - Set 'Copy to output directory' to true.

n8wrl
  • 19,439
  • 4
  • 63
  • 103
  • Thanks! That fixed the DLLs. I don't quite understand how to fix the issue with the log4net.config file. That one is in another project and has it's "Copy to Output Directory" property set to "Copy if newer" (I'm using VS 2010). But it's not getting copied to the Test project's bin\Debug folder, and the test depends upon that project. – Tony Vitabile Oct 17 '11 at 15:58
3

I have found if your tests are being deployed to the test area (true by default), copy local won't work in some circumstances such as dynamic assembly loading.

You can either turn this deployment off by using a runsettings file (https://msdn.microsoft.com/en-us/library/ms182475.aspx) and

<DeploymentEnabled>False</DeploymentEnabled>

Or, a small hack (slightly ugly as it requires manual/hard coding the assembly), by using a DeploymentItem for the binary (mentioned in other answers, but, not specific to handling dlls as per the OP):

[DeploymentItem("bin\\release\\iRock.dll")]
[DeploymentItem("bin\\debug\\iRock.dll")]

Recommend doing both debug/release, depending on what is used on your CI/Dev.

JamesDill
  • 1,857
  • 1
  • 18
  • 22
0

Such dll copying ( apart from referencing them - where you can say Copy Local) and putting them in the out folder should not be part of your tests, but part of your build / packaging process. Have build scripts which do the necessary copying of the dlls.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • The DLLs are referenced but they weren't getting copied. It was because the Copy Local property for those DLLs were false. They're not otherwise a part of the test process, except that they're used by the code. – Tony Vitabile Oct 17 '11 at 16:09
0

When you debug from studio, use Deployment attribute on class or testmethod to copy the required DLLs and config files to the Out folder from where MSTests are run. If you run from command line, use a TestSettings file and disable the Deployment option and set your BIN folder as the working directory. Use/refer this TestSettings file in your command line for running mstest. This way, you can run mstest right in your BIN folder without dumping the DLLs into a out directory. Again, use deployment attribute to debug from studio, there testsettings will not work.

Roy
  • 1