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
1
vote
1 answer

List member equality in FsUnit

I want to check that two lists have the same members, irrespective of order: let memCount items = items |> Seq.countBy id |> Map.ofSeq let memberEquals items1 items2 = memCount items1 = memCount items2 Currently, I use this in a test as…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
1
vote
1 answer

How do I stop my FSUnit tests using F# full syntax

We are using the wonderful FSUnit for our unit testing. This works fine, except the bodies of our tests insist on using full F# syntax (with 'in' at the end of each line etc.) instead of #light syntax. For example: module MyTests open System open…
Kit
  • 2,089
  • 1
  • 11
  • 23
0
votes
0 answers

FsUnit Assert Sequence Containing Float Value

I wanted to assert a sequence using equalSec and equalWithin for a sequence containing float values. I tried seq { System.DateTime(2023, 1, 1), 1.581 } |> should equalSeq (seq { System.DateTime(2023, 1, 1), ((equalWithin 0.01) 1.58) }) but I can't…
Retard
  • 107
  • 1
  • 6
0
votes
1 answer

XUnit/FsUnit framework throwing "Object reference not set to an instance of an objct"

I have written this simple test case for my code module CustomerTests open Xunit open FsUnit open MyProject.Customer open MyProject.Customer.Domain module ``When upgrading customer`` = let customerVIP = {Id = 1; IsVip = true; Credit = 0.0M} …
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
0
votes
1 answer

Testing functions returning option

Consider unit-testing a module defining strings of constrained length as a type for representing user names: module UserName type T = UserName of string let create (userName : string) = if userName.Length >= 6 && userName.Length <= 16 then…
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0
votes
1 answer

F# - (NUnit ApplyTo) member matches multiple overloads ... please restrict it to one

I'm trying to write custom equality constraint to compare 2 objects. open FsUnit open NUnit.Framework.Constraints type equalCompany(expected:Company) = inherit Constraints.EqualConstraint(expected) override this.ApplyTo…
Alex 75
  • 2,798
  • 1
  • 31
  • 48
0
votes
1 answer

Unable to use TestCase with 3 different functions

I am making tests for three functions that make same thing using different ways (with NUnit and FsUnit). I want to use TestCase so I would not have to copy/paste a lot of code. I have this as compilation error message: "This is not a valid constant…
FoRRestDp
  • 185
  • 1
  • 7
0
votes
1 answer

Mock `printfn` in F# tests

I'm trying to write a test for a small lib I'm writing that (essentially) just logs to the console. Is there a way to mock function like this is F#? example: in src/Lib/Lib.fs module Lib let print msg = printfn "Your message is: %s" msg then, in…
David
  • 1,326
  • 9
  • 16
0
votes
2 answers

FsUnit: Unable to test portable library due to it and test project having different F#.Core versions

I have a Portable Library, for which the FSharp.Core version is 3.7.4.0. Installing (in the Unit Test project) FsUnit installs, as a dependency, FSharp.Core version 3.1.2.5. Due to this, using the portable library's functions in my Unit Test…
asibahi
  • 857
  • 8
  • 14
0
votes
0 answers

FsUnit not defined

I'm learning F# recently. Today I wrote some code and tried to add unit tests. I planed to create two projects, one is for code and the other is for test. So I created a new solution called DataLab with a project called Source in Visual Studio 2015…
kuang
  • 687
  • 1
  • 6
  • 17
0
votes
1 answer

Property test ran as unit test fails even though it really passes

It appears that my property test that's running as a unit test fails even though it really passes. The code is as follows: module Tests.Units open FsUnit open NUnit.Framework open NUnit.Core.Extensibility open FsCheck.NUnit open…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
0
votes
1 answer

FsUnit assert exception message

How to assert on exception message in FsUnit? Something like this from NUnit: [] let ShouldThrowExceptionAndLog() = Assert.That ((fun () -> Calculator.Calculate "-1"), …
user963935
  • 493
  • 4
  • 20
0
votes
1 answer

FsUnit - The value or constructor 'should' is not defined

OK so I'm looking at FsUnit to develop tests for some F# code, and I'm having a look at the example BowlingGame.fsx on GitHub. To take the first test: [] let ``with simple scores should get the expected score.`` () = scoreBowls [1;2;3] |>…
Nick
  • 685
  • 12
  • 27
1 2 3
4