Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running F# tests on F# Interactive

I tend to write some quick prototypes on algorithms on F# script files (that I don't really intend to later on migrate into .fs files, although it could well be a possibility) and I'd like to easily test them. What's the quickest way to do some real NUnit/FsUnit tests in F# while running them through F# Interactive?

Well, running them in Visual Studio's Test Runner would be amazing as long as it didn't me bring any extra trouble, I want the KISSest solution possible!

like image 277
devoured elysium Avatar asked Oct 19 '22 00:10

devoured elysium


1 Answers

If you host your script file in an F# Tutorial project then you can run your unit tests defined in the script with Visual Studio's built-in test runner. If you're using NUnit be sure to install the NUnit Test Adapter extension.

#r "nunit.framework.dll"

open NUnit.Framework

[<Test>]
let ``2 + 2 should equal 4`` () =
  Assert.AreEqual(4, 2 + 2)

Alternatively to run a single test just execute the body of your test function or invoke your function:

``2 + 2 should equal 4`` ()

Finally I have an NUnit test runner script that you can use to run batches of tests in F# interactive without needing to copy out the function names, see Running TAP.

like image 67
Phillip Trelford Avatar answered Oct 21 '22 22:10

Phillip Trelford