6

我有一个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.exeC:\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


更新:

在连接时作为错误提交给 MSFT (使用重现步骤 - 在底部的详细信息选项卡下)。

程序集分辨率的现有限制以及强制使用DeploymentItem属性根本无法扩展。冗余维护成本(开发人员被迫手动跟踪单元测试运行所需的依赖项)给测试带来了摩擦。由于这种摩擦而出现的任何问题都很难解决。

4

2 回答 2

3

似乎Runsettings MSDN 文档在元素中有错字Directory,该属性path必须小写才能工作。如果您指定,您的运行设置文件应该可以工作

    <AssemblyResolution>
        <Directory path="C:\Bin\" includeSubDirectories="true" />
    </AssemblyResolution>
于 2017-04-12T10:25:54.693 回答
0

为所有必需的文件设置DeploymentItemAttribute :

[DeploymentItem("Common.dll")]
[DeploymentItem("Common2.dll")]
[TestMethod]
public void TestFoo()
{
    Bar();
}
于 2016-10-05T15:57:42.460 回答