Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS not deploying referenced assembly to test dir when on build server

I have Coded-UI test project that has references to other assemblies in solution. Somehow some assemblies are not copied to TestResults/Out directory, while others are copied. All assemblies have Copy Local option true (don't know if it really matters though) and are absolutely equal in other options. All assemblies are copied when I start test locally from VS2010, but not when on build server.

If I use [DeploymentItem] attribute to force deployment of these "naughty" assemblies they deploy successfully.

I can't get it - I've always thought that if you reference assembly (in References section of Solution Explorer) that assembly will be copied to TestResults/Out and [DeploymentItem] is needed to copy some .xml and other config files.

like image 752
nikita Avatar asked Mar 06 '13 08:03

nikita


1 Answers

I've seen this before. Your test project references other projects but when the tests run you'll notice that the assemblies are not present in the TestRun Out folder.

Unlike other test runners that run unit tests from a fixed location, MSTest copies the assemblies that it requires to a test run folder where the tests are executed. The design allows you to compare test results, coverage, outputs between test runs.

The common misconception is that somehow compilation settings like "Copy Local" will somehow influence which dependencies are used for testing, which is simply not true. MSTest uses reflection to determine assembly references that are required for the test run.

The error you are seeing is likely caused because you've referenced the assembly but the test assembly is not directly using it. You can verify this by using a IL inspection utility (DotPeek, Reflector, etc) to look at the test-assembly references. (This is often a problem in WPF projects that reference assemblies in the XAML.)

To fix, either use the DeploymentSettings to copy the assembly to the output folder; or use the assembly in the test project. For example, adding the following to your test project will emit IL that ensures the assembly is deployed:

var type = typeof(AssemblyNotBeingCopied.MyClass);
like image 160
bryanbcook Avatar answered Oct 27 '22 01:10

bryanbcook