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
15
votes
3 answers

What unit testing frameworks are available for F#

I am looking specifically for frameworks that allow me to take advantage of unique features of the language. I am aware of FsUnit. Would you recommend something else, and why?
GregC
  • 7,737
  • 2
  • 53
  • 67
13
votes
2 answers

How to properly test Exceptions with FsUnit

I'm trying to figure out how to properly test exceptions with FsUnit. Official documentation states, that to test for exceptions I have to right something like this: (fun () -> failwith "BOOM!" |> ignore) |> should throw…
fxdxpz
  • 1,969
  • 17
  • 29
9
votes
4 answers

How to check the case of a discriminated union with FsUnit?

I'd like to check that a value is of a particular case of a discriminated union, without having to also check any included data. My motivation is to only test one thing with each unit test. An example is as follows (the last two lines give…
Mark Pattison
  • 2,964
  • 1
  • 22
  • 42
8
votes
2 answers

Parameterized tests in f# - This is not a valid constant expression

For some reason when passing arguments to the test via TestCase attrubute, I get the following error message about the first argument, which in this case is an array: This is not a valid constant expression or custom attribute value module…
7
votes
1 answer

How to have useful assertion-failure messages for FsUnit?

I'm using FsUnit 2.3.2 and I'm not happy with the failure messages. See the examples below: [] let ``test 1``() = [1; 3] |> should equal [1;2] ... gives me the not-so-helpful message: Expected and actual are both …
vidi
  • 2,056
  • 16
  • 34
7
votes
2 answers

F# How to setup FAKE project that can use FsUnit

I'm trying to setup a basic FAKE F# project that can run FsUnit but I cannot figure out how to solve the Method not found: 'Void FsUnit.TopLevelOperators.should(Microsoft.FSharp.Core.FSharpFunc`2, !!0, System.Object)' errors. I have read…
Danny G
  • 581
  • 4
  • 16
5
votes
2 answers

Comparing Discriminated Unions

I'm a newbie to F# and I'm playing around with FParsec. I would use FParsec to generate an AST. I would like to use FsUnit to write some tests around the various parts of the parser to ensure correct operation. I'm having a bit of trouble with the…
Jeffrey Cameron
  • 9,975
  • 10
  • 45
  • 77
5
votes
1 answer

How can I ignore the value of a discriminated union case in FsUnit's assert?

How can I ignore the value of a discriminated union case in FsUnit's assert? Take for example: type TransactionAttempt = { Deposited:float Requires:float } type RequestResult = | Denied of TransactionAttempt | Granted of…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
5
votes
1 answer

Why can't the NUnit Test Adapter find my FsUnit tests?

I'm using Visual Studio Professional 2015 and I have version 2.0.0.0 of the NUnit Test Adapter installed. It doesn't discover any tests on building the following code: namespace SmallestDivisibleIntegers module Core = let f n = [2..4] |>…
Mark Pattison
  • 2,964
  • 1
  • 22
  • 42
5
votes
2 answers

FsUnit `should equal` fails on `Some []`

When I run this FsUnit test with NUnit 2.6.3, let f xs = Some (List.map ((+) 2) xs) [] let test() = f [] |> should equal (Some []) I get: Result Message: Expected: But was: Result StackTrace: at…
Ming-Tang
  • 17,410
  • 8
  • 38
  • 76
4
votes
1 answer

running fsUnit tests from visual studio

So i wrote my first fsUnit test in Visual studio. It is just an extension to the NUnit framework and I have been using NUnit from doing TDD in C#. While writing tests in c#, I am able to run the tests from visual studio But I am not able to run f#…
gprasant
  • 15,589
  • 9
  • 43
  • 57
4
votes
1 answer

How do I implement multiple argument generation using FsCheck?

How do I implement multiple argument generation using FsCheck? I implemented the following to support multiple argument generation: // Setup let pieces = Arb.generate |> Gen.filter (isKing >> not) |>…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
4
votes
2 answers

Unit testing: '[] |> should equal List.empty' is not working as expected

I have the following code with a test that fails: open Xunit open FsUnit.Xunit let rec openOrSenior xs = match xs with | head :: tail when fst head >= 55 && snd head >= 7 -> "Senior" :: openOrSenior tail | head :: tail -> "Open" ::…
Geert Van Laethem
  • 717
  • 1
  • 8
  • 23
4
votes
1 answer

MissingMethodException when testing a function that takes a function parameter

I am using FsUnit 2.1 (with NUnit 3.2) to write tests for an F# project. Here is a simple module: namespace Library1 module LibraryFunctions = let Execute f1 = f1() let Id x = x And here are my tests: namespace Tests open FsUnit open…
Blisco
  • 601
  • 6
  • 14
4
votes
1 answer

How to use NUnit with F# properly?

I have stucked with the unit testing. I have the following source code: module SampleTest open FsUnit open NUnit.Framework [] [] type DoSthTest() = let mutable state = [] [] member…
aph5
  • 771
  • 2
  • 7
  • 23
1
2 3 4