1

I've installed Visual Studio 2017 and included the test package and the F# package. I'm trying to run a simple test using xUnit but it says xUnit is not found.

module HelloWorldTest

open FsUnit.xUnit
open Xunit

open System.Diagnostics

[<Fact>]
let ``Say Hello`` () =
    Assert.True(true)

Error

The namespace or module 'FsUnit' is not defined.

I tried installing the package with dotnet but that produces an error.

> dotnet add package FSharp.xUnit 
  Writing C:\Temp\tmp8DAB.tmp
info : Adding PackageReference for package 'FSharp.xUnit' into project  'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
log  : Restoring packages for C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj
...
error: Unable to find package FSharp.Core. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package FsUnit.xUnit. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package xunit. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package xunit.runner.visualstudio. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package FSharp.xUnit. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package Microsoft.NET.Test.Sdk with version (>= 16.0.0)
error:   - Found 1 version(s) in Microsoft Visual Studio Offline Packages [ Nearest version: 15.9.0]
error: Package 'FSharp.xUnit' is incompatible with 'all' frameworks in project 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.

So how can I install xUnit for F#? This guide from MS unfortunately is lacking any of this information. https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-dotnet-test

EDIT:

After adding the NuGet package source

> dotnet add package FsUnit.xUnit
  Writing C:\Temp\tmp5BA6.tmp
info : Adding PackageReference for package 'FsUnit.xUnit' into project 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
log  : Restoring packages for C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj
...
info :   CACHE https://api.nuget.org/v3-flatcontainer/fsunit.xunit/index.json
info : Package 'FsUnit.xUnit' is compatible with all the specified frameworks in project 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
info : PackageReference for package 'FsUnit.xUnit' version '3.4.0' updated in file 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
dangeroushobo
  • 1,291
  • 2
  • 16
  • 28
  • 1
    Your debug output makes it seem like your project is not configured to look at nuget as a package source, try following [this](https://stackoverflow.com/a/50484648/1346943) – Sven Grosen Mar 05 '19 at 15:33
  • This helped get the packages added via running `dotnet` but during building I'm still getting `The namespace or module 'FsUnit' is not defined.`. – dangeroushobo Mar 05 '19 at 16:30
  • I tried installing `FsUnit` via nuget in a F# application and was able to get it to compile with a `open FsUnit.Xunit` line at the top, are you sure the packages were all installed appropriately? – Sven Grosen Mar 05 '19 at 16:35
  • See my edit to the original post, I didn't see any error message. Is there any other way to verify? I'm new to all things .Net. – dangeroushobo Mar 05 '19 at 18:11
  • Try `dotnet list package`. I've tried this multiple times and it works fine for me (admittedly via LinqPAD, but it should be the same regardless of the IDE/editor). – Sven Grosen Mar 05 '19 at 18:17
  • When I run `dotnet list package` I get an error, `Required command was not provided.`. – dangeroushobo Mar 05 '19 at 18:56
  • What is your target framework? Here is a link to a working fsproj (can ignore Expecto for your case). https://github.com/dburriss/FsharpUnitTestFrameworks/blob/master/TestFrameworks/TestFrameworks.fsproj – Devon Burriss Mar 17 '19 at 16:43

0 Answers0