我有一个UnitTests.dll
,其中引用了Common.dll
(都是使用VS2015构建的)。
我有以下目录结构:
C:\Test\
- UnitTests.dll
- UnitTests.runsettings
C:\Bin\
- Common.dll
UnitTests.runsettings
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<TargetPlatform>x64</TargetPlatform>
</RunConfiguration>
<MSTest>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
<CaptureTraceOutput>False</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>False</DeploymentEnabled>
<AssemblyResolution>
<Directory Path="C:\Bin\" includeSubDirectories="true" />
</AssemblyResolution>
</MSTest>
</RunSettings>
我调用了测试:
C:\Test> vstest.console.exe UnitTests.dll /settings:UnitTests.runsettings /inIsolation
vstest.console.exe
指 C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ CommonExtensions \ Microsoft \ TestWindow \ vstest.console.exe 。
我收到以下错误:
Starting test execution, please wait...
Failed TestMethod1
Error Message:
Test method UnitTests.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Stack Trace:
at UnitTests.UnitTest1.TestMethod1()
更多,启用Fusion Log:
Starting test execution, please wait...
Failed TestMethod1
Error Message:
Test method UnitTests.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
=== Pre-bind state information ===
LOG: DisplayName = Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Test
LOG: Initial PrivatePath = NULL
Calling assembly : UnitTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
=== LOG: This bind starts in default load context.
LOG: Using application configuration file:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Test/Common.DLL.
LOG: Attempting download of new URL file:///C:/Test/Common/Common.DLL.
LOG: Attempting download of new URL file:///C:/Test/Common.EXE.
LOG: Attempting download of new URL file:///C:/Test/Common/Common.EXE.
Stack Trace:
at UnitTests.UnitTest1.TestMethod1()
我是否面临某种缓存问题?如何说服vstest.console.exe
寻找C:\Bin\
内的依赖关系(理论上由AssemblyResolution
元素指出)?
更新
Submitted as a bug to MSFT on connect (使用repro步骤 - 在底部的DETAILS选项卡下)。
装配解决方案的现有限制以及强制使用DeploymentItem
属性,根本无法扩展。冗余维护成本(开发人员被迫手动跟踪单元测试运行所需的依赖关系)会给测试带来摩擦。由于这种摩擦而出现的任何问题都很难排除故障。
答案 0 :(得分:1)
似乎Runsettings MSDN documentation在Directory
元素中有拼写错误,属性path
必须小写才能正常工作。如果指定
<AssemblyResolution>
<Directory path="C:\Bin\" includeSubDirectories="true" />
</AssemblyResolution>
答案 1 :(得分:0)
为所有必需文件设置DeploymentItemAttribute:
[DeploymentItem("Common.dll")]
[DeploymentItem("Common2.dll")]
[TestMethod]
public void TestFoo()
{
Bar();
}