如何在F#中从控制台运行Nunit测试

时间:2017-05-17 01:13:21

标签: visual-studio f# nunit nunit-console

我有一个用F# 4.1编写的项目,使用Nunit 3.6.1。我使用VisualStudio 2017来构建项目,使用NUnit Console Runner 3.6.1来运行测试。但是,当我尝试运行我的测试时,会收到一个错误:

  

C:\ projects \ AzureLogsDownloader \ packages \ NUnit.ConsoleRunner.3.6.1 \ tools> nunit3-console.exe“C:\ projects \ AzureLogsDownloader \ AzureLogs.Core.Tests \ bin \ Debug \ AzureLogs.Core.Tests .DLL“

     

无法加载文件或程序集'FSharp.Core,Version = 4.4.1.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。系统找不到指定的文件。(HRSULT:0x80131040)

我尝试将FSharp.Core复制到测试跑步者的文件夹,但它没有帮助。

如何修复此问题并运行我的测试?

1 个答案:

答案 0 :(得分:0)

只有几个必要的步骤:

  1. 在测试项目中创建app.config文件
  2. 添加此示例中显示的bindingRedirects(我假设您使用的是NUnit 3.6.1):
  3. <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.4.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="NUnit.Framework" publicKeyToken="2638cd05610744eb" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="3.6.1.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
      </startup>
    </configuration>