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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With