Question

I'm new to F# and I intend to create new F# project, and unit test it with F# in Visual Studio 2008, but the Visual Studio 2008 Unit Test Wizard don't have a F# test project option (just have C, C# and VB options).

  1. Is it possible to unit test F#?
  2. Is it possible to unit test F# with a F# test project?
  3. Is it possible to unit test F# with a F# test project in Visual Studio 2008?
  4. How to do it, if there is no Wizard in Visual Studio 2008?
Was it helpful?

Solution

This link describes using the VS testing system with F#. You do it pretty much the same way as with C#.

The downside is that apparently the VS IDE won't automatically pick it up -- I believe you need to run from the command line using mstest.exe.

Edit: Oh, another cool thing with F#, is FsCheck. This allows you to write simple tests, and have the FsCheck system try to disprove them via random testing.

OTHER TIPS

I found this article on f# testing with nunit (link here). I do remember however that there's another way to verify the validity of functional language code (I 'worked' with Clean, which is similar to Haskell for my bachelor). Just can't remember exactly what they called it, I do remember it's more like a mathematical proof. Also, I'm not sure that it works for F#, as it's a bit different from Haskell'esque languages if I read that correctly.

  1. If you're generating .NET code, it is possible to unit test F# with nunit, as long as the interface is reasonably CLI compliant.
  2. Nunit works with .NET assemblies, not with any particular language. If you can drop the [TestFixture] attribute on a class and can drop the [Test] attribute on a public method in a particular class, which returns void, then NUnit can run it.
  3. Don't know.
  4. Don't know.

There's nothing forcing you to use F# to test F#. You could simply create a unit test assembly in C#, VB or another .NET supported language, and simply reference the F# assembly needed to perform the tests. You would do it just as you would create unit tests for any other .NET assembly.

I'm not sure whether this is strictly related to your exact question, but there are a whole series of posts on Matthew Podwysocki's blog about unit testing in functional languages - there are some F# bits in there too.

  • Part 1 - xUnit Frameworks - HUnit
  • Part 2 - Property-Based Tests - QuickCheck
  • Part 3 - QuickCheck + xUnit Tests Together
  • Part 4 - Code Coverage
  • Part 5 – Keeping Things Pure
  • Part 6 – Monadic Abstractions
  • Aside – Using Type Classes
  • Part 7 - Improving Your Codebase

Are you asking if it's possible to unit test in F# or are you asking if there's a wizard for it? It's possible to unit test in any language, in fact, functional languages are a unit testers wet dream (I heard it described that way.) since everything is static and you've verified all the edge cases you've essentially verified every case.

EDIT: To answer the fourth question, write your own test cases:

http://en.wikipedia.org/wiki/Unit_testing

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top