views:

724

answers:

6

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?
+1  A: 

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

Spencer Ruport
I added a 4th question, please look
Jader Dias
+3  A: 

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.

Erik van Brakel
+2  A: 

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.

David Morton
Okay, I don't need it, but I want it.
Jader Dias
Except creating F# types from C# can be extremely painful, unless the F# code is aimed at being a nice .NET OO class.
MichaelGG
Here is an example to convert between F# and C# lists:http://stackoverflow.com/questions/661095/retrieving-items-from-an-f-list-passed-to-c
Tuomas Hietanen
+3  A: 
  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.
plinth
+3  A: 

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.

MichaelGG
+2  A: 

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
Benjol
not exactly about F#. From what I readed is more about another functional language: Haskell
Jader Dias
My bad, I didn't look properly - but I think there are comparisons with F# solutions in there too.
Benjol
And if you look really carefully, the third link in your accepted answer links back to these blog posts ;)
Benjol