Structuring Test Data I'm just getting started with F# and was writing some unit tests for some functionality I had written. In the interest of brevity, I decided to create some lists of the different test cases and just run through them all in one test instead of creating separate test methods for each one (I'm not focusing on that design decision here, just pointing it out as otherwise my question won't make much sense).

So here's my code:

// simple helper to cut down on repeated code
let testRunner cases func =
    cases |&gt; List.map func

// isNumeric is the function under test, its functionality should be obvious
[&lt;Test&gt;]
let ``IsNumericTest``() =
    let testCases = ["123"; "Foo"; "123Foo123"]
    let expectedResults = [true; false; false]
    let results = testRunner testCases isNumeric
    results |&gt; should equal expectedResults


I started thinking about creating a simple type to encapsulate the test case input and the expected result, something like this:

type TestCase = { Input : string; ExpectedResult : bool}

type TestCases = TestCase list

let testCases = [{Input="123"; ExpectedResult=true};{Input="Foo"; ExpectedResult=false}; {Input="123Foo123"; ExpectedResult=false}]


Then I struggled to think of how to split each of those down to use in my testRunner method until I came up with this:

let results = testRunner (testCases |&gt; List.map (fun (T) -&gt; T.Input)) isNumeric
results |&gt; should equal (testCases |&gt; List.map (fun (T) -&gt; T.ExpectedResult))


But that just looks ugly. Is there a better way to split out the Input value for my testRunner method? I am fine with changing it, but figured that while my question is specific to a unit testing scenario, the lessons I should learn would be widely applicable.
Since you're on NUnit, why don't you just use its built-in TestCase attribute? Your test would then look like this:

[&lt;TestCase("123", true)&gt;]
[&lt;TestCase("Foo", false)&gt;]
[&lt;TestCase("123Foo123", false)&gt;]
let ``IsNumericTest``(candidate : string, expected : bool) =
    let actual = isNumeric candidate
    actual |&gt; should equal expected


xUnit.net (a better unit testing framework for .NET) has a similar feature.