Reputation: 1308
I need to run unit tests from an assembly where the assembly already exists. Visual Studio (2012) is copying that assembly to some generated deployment location and is testing from there. How can I prevent that?
According to this page on How to: Deploy Files for Tests, unit tests are only deployed to some directory when there are DeploymentItem attributes being used.
If you run tests by using Visual Studio, the deployment folder is created under TestResults in your solution folder. A separate deployment folder is used if any of the test methods or classes in a test run has the DeploymentItem attribute, or if you use a .testsettings file.
I don't have any DeploymentItem attributes, yet the following test is failing because the unit test is being run from some generated directory, not the build output directory. I've also tried creating a .runsettings file and ensuring "Enable Deployment" is unchecked, but Visual Studio seems to ignore that.
[TestClass]
public class UnitTests
{
private void RunAssemblySelfTests(string assemblyName)
{
Assembly assembly = Assembly.LoadFrom(assemblyName + ".dll");
//...load and run tests that use in-house testing framework
}
[TestMethod]
public void MyAssemblyTest()
{
RunAssemblySelfTests("MyAssembly");
}
}
The UnitTests assembly's build output directory is the same directory as MyAssembly, and I've confirmed that they both exist there. When run, the test fails because of this exception:
Result Message:
Test method MyNameSpace.UnitTests.MyAssemblyTest threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'file:///[path to solution]\SolutionName\TestResults[user name]_[computer name] 2013-08-28 13_35_10\Out\MyAssembly.dll' or one of its dependencies. The system cannot find the file specified.
I can't deploy any test assemblies, even without this reflection stuff going on, because the dependencies result in several GB.
Upvotes: 2
Views: 2712
Reputation: 1308
I finally figured it out. Although there were no references to these leftover VS 2010 files in the solution, VS 2012 was still using them for some reason. Deleting them both fixed the problem:
Visual Studio still creates a TestResults folder, but it isn't deploying the file and entire solution's source code anymore.
Upvotes: 4