测试项目没有找到测试的项目DLL

时间:2015-01-14 20:37:50

标签: unit-testing c#-4.0

我想知道我是否可以实施此处列出的建议:

http://www.ndepend.com/Res/NDependWhiteBook_Assembly.pdf

  • 我将主项目设置为命令行应用程序。
  • 我的测试项目使用copylocal = false引用我的cmdlnApp。
  • 我的主项目设置输出到.. \ build \ debug(调试时)
  • 我的测试项目设置输出到.. \ build \ tests \

我的测试项目中有一个app.config,其中包含以下设置:

<configuration>
    <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <probing privatePath="debug;debug\lib;tests;" />
                <dependentAssembly>
                        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
                </dependentAssembly>
            </assemblyBinding>
    </runtime>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
    </startup>
</configuration>

当我尝试运行单元测试时,收到错误:     System.IO.FileNotFoundException:无法加载文件或程序集'CmdLnApp,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'或其依赖项之一。

我已经检查并且正在创建构建文件夹,调试文件夹包含来自CmdLnApp的所有文件,构建文件夹也有一个包含所有测试库的tests文件夹。

有人能看到我错过的东西吗?

1 个答案:

答案 0 :(得分:0)

经验法则:所有代码都必须在外部DLL中。它使它更容易测试。 exe中的任何内容都可以由用户,UI自动化测试或通过命令行参数调用exe来测试。所有这些都很麻烦并且容易失败。纠正您的设置,您将没有任何问题。