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

1

5

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.

Cymoid answered 6/3, 2013 at 8:4 Comment(2)
What is the relationship of these assemblies to your project - are they project references or statically linked (3rd party libraries, etc)?Lavender
They are project references.Cymoid
L
14

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);
Lavender answered 8/3, 2013 at 19:12 Comment(3)
Thanks for suggestion, but it didn't help. I've added typeof statements to test method, but MSTest still doesn't deploy several assemblies.Cymoid
Worked for me. Check that the type that you reference is in the assembly you want to load.Ideation
I had a issue related to that and couldn't find the answer anywhere. Thank you so much. Does anybody know if MSTest still works this way in its current versions?Chairwoman

© 2022 - 2024 — McMap. All rights reserved.