Maxim Kitsenko
Maxim Kitsenko

Reputation: 2333

How to run Nunit test in F# from console

I have a project written in F# 4.1 which uses Nunit 3.6.1. I use VisualStudio 2017 to build a projects and NUnit Console Runner 3.6.1 to run tests. But when i try to run my tests a receve an error:

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"

Could not load file or assembly 'FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.(HRSULT: 0x80131040)

I tried to copy FSharp.Core to test runner's folder, but it doesn't help.

How fix this issue and to run my tests?

Upvotes: 1

Views: 453

Answers (1)

Dzoukr
Dzoukr

Reputation: 1145

There are just few necessary steps:

  1. Create app.config file in your test project
  2. Add bindingRedirects like shown in this sample (I assume that you are on NUnit 3.6.1):
<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>

Upvotes: 0

Related Questions