I would like to be about to use a list, array, and/or seq as a parameter to xUnit\'s InlineData.
In C# I can do this:
using Xunit; //2.1.0
namespace C
You can use the FSharp.Reflection
namespace to good effect here. Consider some hypothetical function isAnswer : (string -> int -> bool)
that you want to test with a few examples.
Here's one way:
open FSharp.Reflection
open Xunit
type TestData() =
static member MyTestData =
[ ("smallest prime?", 2, true)
("how many roads must a man walk down?", 41, false)
] |> Seq.map FSharpValue.GetTupleFields
[)>]
let myTest (q, a, expected) =
Assert.Equals(isAnswer q a, expected)
The key thing is the |> Seq.map FSharpValue.GetTupleFields
line.
It takes the list of tuples (you have to use tuples to allow different arguments types) and transforms it to the IEnumerable
that XUnit expects.