简体   繁体   中英

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!

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM