We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Tyson Williams • 6 years ago

In trying to get xUnit's MemberData attribute working in F#, I found this blog post the most helpful. What I found a bit confusing though was that the given example doesn't compile straight away. Here are my changes that achieve that while also trying to remove as many unnecessary details as possible. (This site doesn't preserve whitespace at the beginning of new lines, so I used the dash character instead. So copy-paste this code then replace the dash character with a space character.)

module TestModule
--open Xunit
--type TestType () =
----static member TestProperty
------with get() : obj[] list =
--------[
----------[| 0; "a" |]
----------[| 1; "b" |]
--------]
----[<theory>]
----[<memberdata("testproperty")>]
----member __.TestMethod (a:int) (b:string) =
------Assert.Equal<int>(0, a)

Assassyn • 6 years ago

Simples way is to use MemberData attribute:

let memberDataProperty:=
seq {
yield [|"param1":> Object; param2 :> Object; expectedResult :> Object |]
}

[<theory>]
[<memberdata("memberdataproperty")>]
let ``Can use MemberData`` param1 param2 expectedResult =