Questions tagged [fsunit]

FsUnit is a set of libraries that makes unit-testing with F# more enjoyable. It adds a special syntax to your favorite .NET testing framework.

FsUnit is a set of libraries that makes unit-testing with F# more enjoyable. It adds a special syntax to your favorite .NET testing framework. FsUnit currently supports NUnit, MbUnit, xUnit, and MsTest (VS11 only).

The goals of FsUnit are:

  • to make unit-testing feel more at home in F# , i.e., more functional.
  • to leverage existing test frameworks while at the same time adapting them to the F# language in new ways.
58 questions
4
votes
1 answer

F# and NUnit: Structured output of record types on test failure

I'm using NUnit to unit test F# code using Resharper's test runner inside Visual Studio 2013. I have several F# record and discriminated union types in the projects and functions that return instances of these types, such as: type MyRecord = { A :…
Axel Habermaier
  • 263
  • 3
  • 9
4
votes
1 answer

Using TestCase with fsunit

I have been trying to use fsunit to test a project. If I limit myself to [] methods they all show up in the TestExplorer. However, if I try to use [] nothing shows up and no tests get executed. I expect I have something…
melston
  • 2,198
  • 22
  • 39
4
votes
1 answer

Assert Some with FsUnit

I am trying to check that my function returns Some(x) testedFunc() |> should be (sameAs Some) testedFunc() |> should be Some testedFunc() |> should equal Some All don't work. I'd rather not use: match testedFunc() with | Some -> Pass() |…
Paul Nikonowicz
  • 3,883
  • 21
  • 39
3
votes
1 answer

FsUnit.Xunit list should contain an x such that f x

I am not sure how to write my test in FsUnit.Xunit. I want to check that at least one element in my list satisfies a predicate. I know how to write this using should be True, but usually you can get better error messages by using the specialized…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
3
votes
1 answer

F# - How to test an exception raised in the constructor with fsunit?

I want to check if an argument passed to the constructor of a type is valid. I check it and raise an ArgumentException if not valid. I want to create a test for this behavior. I want to use Assert.throws or preferably FSUnit instead of a try/with…
Alex 75
  • 2,798
  • 1
  • 31
  • 48
3
votes
1 answer

Asserting exception message using FsUnit.Xunit

I'm trying to assert a certain exception type and message using FsUnit.Xunit. There is some throwWithMessage function that comes with FsUnit. However, when using it instead of the throw function fsc emits the following errors: C:\src\foo.fs(29,12):…
jasper
  • 521
  • 4
  • 17
3
votes
1 answer

How to create a fsunit test for pattern matching in f#?

I'm new to f# and fsUnit and I'm wondering how to test a pattern matching statement using fsUnit. For example, if i have the following code how would you write a fsunit test for it? let Menu () = let Choice = Console.ReadLine() match…
Chimmy
  • 95
  • 7
3
votes
0 answers

FsUnit.xUnit FSharp.Core and xunit.assert assembly binding

I am taking my first steps with F# and testing with FsUnit.xUnit. In Visual Studio 2017 I set up a brand new F# project and add a test project. To the test project I NuGet FsUnit.xUnit 3.0.0 and then NuGet FsUnit.xUnit.Sample. Everything…
FSharpOrBust
  • 115
  • 3
3
votes
2 answers

Asserting exception in FsUnit F# for XUnit

I am trying to assert that an exception was thrown. Here is a cut down piece of code that reproduces the problem: open FsUnit open Xunit let testException () = raise <| Exception() [] let ``should assert throw correctly``() = …
Kevin Holditch
  • 5,165
  • 3
  • 19
  • 35
3
votes
0 answers

FsUnit.xUnit FSharp.Core assembly binding

I'm trying to write a unit test project using FSUnit.xUnit. Throughout my development on this process, I have been plagued by tests failing with this message (not always citing the same version): Could not load file or assembly 'FSharp.Core,…
Rob Lyndon
  • 12,089
  • 5
  • 49
  • 74
3
votes
2 answers

FsUnit and checking equality of floating point numbers

I started using FsUnit to test F# code. It makes it possible to express assertion in F# style, for example: [] member this.``Portugal voted for 23 countries in 2001 Eurovision contest``() = this.totalVotes |> getYearVotesFromCountry…
Vagif Abilov
  • 9,835
  • 8
  • 55
  • 100
3
votes
1 answer

F# unit testing: nunit.framework assembly not referenced error

I'm playing with unit testing in F#. I'm running Visual Studio 2013 Community Edition. I created a test project and installed NUnit 2.6.4 and FsUnit 1.3.0.1. I used Package Manager Console. I added references to the libraries in the project and in…
PiotrWolkowski
  • 8,408
  • 6
  • 48
  • 68
3
votes
1 answer

fsunit.xunit test exception in constructor

Having type Category(name : string, categoryType : CategoryType) = do if (name.Length = 0) then invalidArg "name" "name is empty" i'm trying to test this exception using FsUnit + xUnit: [] let ``name…
Dzmitry Martavoi
  • 6,867
  • 6
  • 38
  • 59
3
votes
2 answers

FsUnit, NUnit references in an F# project

I have a solution in Visual Studio 2012. It includes two projects for tests, one in F# and one in C#. I have installed NUnit and FsUnit as Nuget packages. After the installation, the references to these assemblies point to the dll's found in the…
Panos
  • 617
  • 7
  • 20
3
votes
2 answers

Error on FsUnit example

I copied this example from the FsUnit project page: open NUnit.Framework open FsUnit let [] trivial () = 1 |> should not (equal 2) F# gives me the following error: Error 2 This expression was expected to have type bool but here…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699