Question

I copied this example from the FsUnit project page:

open NUnit.Framework
open FsUnit
let [<Test>] trivial () = 1 |> should not (equal 2)

F# gives me the following error:

Error 2 This expression was expected to have type bool but here has type Constraints.EqualConstraint

Error 1 The type 'bool' is not compatible with the type 'Constraints.Constraint'

What am I doing wrong?

Was it helpful?

Solution

A newer version of FsUnit includes a change that renames the FsUnit.not function to FsUnit.not'. This should eliminate the conflict with the built-in not function. You can get the latest version from NuGet Gallery. Examples of use can be found on the FsUnit GitHub site.

Let me know if you still see the issue. I'll be happy to do some more in-depth troubleshooting with you.

OTHER TIPS

I think there is something wrong with the way you're referencing FsUnit. I tried to run your code (just copy FsUnit source code from CodePlex) and it worked fine. You still need to write your test as a function (as pointed out by Joel) so write something like let [<Test>] trivial () = ....

For some reason, I think your script is using the built-in not function (that operates on bool values) instead of the FsUnit.not function that operates on Constraint objects. Does it work if you use the not function from FsUnit explicitly?

let cnot = FsUnit.not
let [<Test>] trivial = 1 |> should cnot (equal 1) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top