Testing with F#

F# is Microsoft’s new programming language. F# is scheduled to ship with the next version of Visual Studio but a Community Technical Preview version is available. F# is a functional language which means among other things that most language constructs are related to functions and return values. I’ve had quite a bit of experience with Prolog and LISP, two old functional languages and I never really liked them very much. But I’ve been looking at F# and like what I’ve seen so far. For test automation, one traditional, non-functional approach is to create test case data and then iterate through the data. Here is a snippet of what this might look like with F#:
let testCases =
  [ "001,3,5,8"
let dummy =
  Seq.iter(fun(testCase) ->
  let delimits = [|’,’;’~’|];
  let tokens = testCase.Split(delimits)
  let caseID = tokens.[0]
  let input1 = tokens.[1]
  let input2 = tokens.[2]
  let expected = tokens.[3]
  // send input1 & input2 to SUT
  // check actual return with expected
  if actual == expected then
    printfn "Pass"
  else printfn "Fail"
The first part of the snippet sets up an F# List object of test case input. The second part of the snippet uses Seq.iter (sequence iterator) to process each item in the List by applying an anonymous function (indicated by the "fun" keyword) which always returns true. Like anything else, it takes a while to get up to speed with F# but so far it’s been an interesting investigation.
This entry was posted in Software Test Automation. Bookmark the permalink.